﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
//using Hongye.CGAL;
using YArchitech.DataModel;
using YArchitech.HVAC;
using YArchitech.Plumbing.GroundStorehouseNozzles;
using YArchitech.Plumbing.Model;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public class GroundStorehouseNozzle
	{
		public static Element GetNearRoom(Autodesk.Revit.DB.Document doc, XYZ locPoint)
		{
			double num = (double)3000 / 304.8;
			XYZ point = new XYZ(locPoint.X - num, locPoint.Y + num, locPoint.Z);
			XYZ point2 = new XYZ(locPoint.X + num, locPoint.Y - num, locPoint.Z);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(RevitAPIUIOperate.GetViewRange2(doc.ActiveView, false), point, point2), 0.001);
			Element[] array = new FilteredElementCollector(doc).WherePasses(boundingBoxIntersectsFilter).ToArray<Element>();
			Element result = null;
			foreach (Element element in array)
			{
				if ((element is Space || element is Room) && element.Name.Contains("车库"))
				{
					List<Element> list = new List<Element>();
					list.Add(element);
					List<Curve> lstCurves = new List<Curve>();
					if (GroundStorehouseNozzle.GetListList(list, ref lstCurves) != null && GroundStorehouseNozzle.PointInPloygon(lstCurves, locPoint) != -1)
					{
						return element;
					}
				}
			}
			return result;
		}

		public static FilledRegion CreateRegion(UIApplication uiApp, List<Curve> lstTempMerge, bool bl = false)
		{
			Document document = uiApp.ActiveUIDocument.Document;
			FilledRegion result = null;
			System.Drawing.Color color = System.Drawing.Color.FromArgb(255, 0, 0);
			if (bl)
			{
				color = RevitVersionFuncs.GetViewBackgroundColor(uiApp.Application);
			}
            Autodesk.Revit.DB.Color clr = new Autodesk.Revit.DB.Color(color.R, color.G, color.B);
			Transaction transaction = new Transaction(document, "c");
			try
			{
				transaction.Start();
				FilledRegionType type = GroundStorehouseNozzle.CreateFilledRegionType(document, clr, "NULL");
				CurveLoop curveLoop = new CurveLoop();
				foreach (Curve curve in lstTempMerge)
				{
					curveLoop.Append(curve);
				}
				result = GroundStorehouseNozzle.CreateFilledRegion(document, curveLoop, type);
				transaction.Commit();
			}
			catch (Exception ex)
			{
				ex.ToString();
				transaction.RollBack();
			}
			return result;
		}

        private static FilledRegionType CreateFilledRegionType(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.Color clr, string strName = "NULL")
		{
			if (strName == "NULL")
			{
				strName = string.Concat(new string[]
				{
					"纯色填充R",
					clr.Red.ToString(),
					"G",
					clr.Green.ToString(),
					"B",
					clr.Blue.ToString()
				});
			}
			IList<Element> source = new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType)).ToElements();
			IEnumerable<FilledRegionType> source2 = from FilledRegionType pattern in source
			where pattern.Name.Equals(strName)
			select pattern;
			if (source2.Count<FilledRegionType>() != 0)
			{
				return source2.First<FilledRegionType>();
			}
			IEnumerable<FillPatternElement> source3 = from FillPatternElement patElement in new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).ToElements()
			where patElement.Name.Equals("实体填充") || patElement.Name.Equals("<实体填充>")
			select patElement;
			if (source3.Count<FillPatternElement>() != 1)
			{
				return null;
			}
			FillPatternElement fillPatternElement = source3.First<FillPatternElement>();
			FilledRegionType filledRegionType = (source.First<Element>() as FilledRegionType).Duplicate(strName) as FilledRegionType;
			if (filledRegionType.get_Parameter(BuiltInParameter.ANY_PATTERN_ID_PARAM_NO_NO) != null)
			{
				filledRegionType.get_Parameter(BuiltInParameter.ANY_PATTERN_ID_PARAM_NO_NO).Set(fillPatternElement.Id);
			}
			if (filledRegionType.get_Parameter((BuiltInParameter)(-1002122)) != null)
			{
				filledRegionType.get_Parameter((BuiltInParameter)(-1002122)).Set(fillPatternElement.Id);
			}
			if (filledRegionType.get_Parameter((BuiltInParameter)(-1002121)) != null)
			{
				filledRegionType.get_Parameter((BuiltInParameter)(-1002121)).Set(fillPatternElement.Id);
			}
			int num = (int)clr.Red + (int)clr.Green * 256 + (int)clr.Blue * 256 * 256;
			filledRegionType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(num);
			filledRegionType.get_Parameter(BuiltInParameter.LINE_PEN).Set(1);
			return filledRegionType;
		}

		private static FilledRegion CreateFilledRegion(Autodesk.Revit.DB.Document doc, CurveLoop loopCvs, FilledRegionType type)
		{
			FilledRegion result = null;
			List<CurveLoop> list = new List<CurveLoop>();
			list.Add(loopCvs);
			try
			{
				result = FilledRegion.Create(doc, type.Id, doc.ActiveView.Id, list);
			}
			catch
			{
			}
			return result;
		}

		public List<Curve> RoomAndGridSegment(Autodesk.Revit.DB.Document doc, List<List<Curve>> lstlstIn, List<Curve> outCurves, IList<Element> column)
		{
			List<Grid> specifyElements = GroundStorehouseNozzle.GetSpecifyElements(doc);
			List<Curve> list = new List<Curve>();
			foreach (Grid grid in specifyElements)
			{
				Curve curve = grid.Curve;
				list.Add(curve);
			}
			list = this.GetValidGridCurves(doc, lstlstIn);
			list = this.GetlistGrid(doc, list, column);
			return this.GetAllCurves(lstlstIn, list, outCurves, doc);
		}

		private List<Curve> GetlistGrid(Autodesk.Revit.DB.Document doc, List<Curve> allGridCurve, IList<Element> column)
		{
			List<List<Curve>> columnCurves = this.GetColumnCurves(doc, column);
			List<Curve> list = new List<Curve>();
			foreach (Curve curve in allGridCurve)
			{
				YJKLine hyline = new YJKLine(GroundStorehouseNozzle.SetZValue(curve.GetEndPoint(0), 0.0), GroundStorehouseNozzle.SetZValue(curve.GetEndPoint(1), 0.0));
				List<XYZ> list2 = new List<XYZ>();
				foreach (List<Curve> list3 in columnCurves)
				{
					foreach (Curve curve2 in list3)
					{
						if (hyline.IntersectionPoint(curve2 as Line) != null)
						{
							list2.Add(this.GetCenterPoint(list3));
							break;
						}
					}
				}
				if (list2.Count >= 2)
				{
					List<XYZ> farestTwoPoints = this.GetFarestTwoPoints(list2);
					list.Add(Line.CreateBound(farestTwoPoints[0], farestTwoPoints[1]));
				}
			}
			return list;
		}

		private List<List<Curve>> GetColumnCurves(Autodesk.Revit.DB.Document doc, IList<Element> column)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			foreach (Element collisionEle in column)
			{
				List<Curve> clomnCurveList = this.GetClomnCurveList(doc, collisionEle, 0.0);
				list.Add(clomnCurveList);
			}
			return list;
		}

		private XYZ GetCenterPoint(List<Curve> lstCurve)
		{
			int num = lstCurve.Count * 2;
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			foreach (Curve curve in lstCurve)
			{
				xyz += curve.GetEndPoint(0) + curve.GetEndPoint(1);
			}
			return xyz / (double)num;
		}

		private List<XYZ> GetFarestTwoPoints(List<XYZ> points)
		{
			List<XYZ> list = new List<XYZ>();
			double num = 0.0;
			XYZ item = XYZ.Zero;
			XYZ item2 = XYZ.Zero;
			for (int i = 0; i < points.Count - 1; i++)
			{
				for (int j = i + 1; j < points.Count; j++)
				{
					if (points[i].DistanceTo(points[j]) > num)
					{
						num = points[i].DistanceTo(points[j]);
						item = points[i];
						item2 = points[j];
					}
				}
			}
			list.Add(item);
			list.Add(item2);
			return list;
		}

		public static bool GetBlLess(List<Curve> lst)
		{
			double num = 7.8740157480314954;
			foreach (Curve curve in lst)
			{
				if (curve.GetEndPoint(0).DistanceTo(curve.GetEndPoint(1)) <= num)
				{
					return true;
				}
			}
			return false;
		}

		public static DetailCurve DrawCurve(Autodesk.Revit.DB.View activeView, Autodesk.Revit.DB.Document doc, Curve curve, Category lineStyle)
		{
			DetailCurve result;
			try
			{
				string strB = "不规则区域标注" + " " + 15;
				GraphicsStyle lineStyle2 = null;
				foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle)))
				{
					GraphicsStyle graphicsStyle = element as GraphicsStyle;
					if (graphicsStyle != null && graphicsStyle.Name.CompareTo(strB) == 0)
					{
						lineStyle2 = graphicsStyle;
					}
				}
				DetailCurve detailCurve = doc.Create.NewDetailCurve(activeView, curve);
				if (detailCurve != null)
				{
					detailCurve.LineStyle = lineStyle2;
				}
				result = detailCurve;
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}

		public static bool CreateLineStyle(Autodesk.Revit.DB.Document m_Doc, ref Category lineCategory)
		{
			string text = "不规则区域标注";
			string text2 = text + " " + 15;
            Autodesk.Revit.DB.Color lineColor = new Autodesk.Revit.DB.Color(byte.MaxValue, 0, 0);
			int num = 15;
			Category category = m_Doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
			if (category == null)
			{
				return false;
			}
			if (category.SubCategories.Contains(text2))
			{
				return false;
			}
			Transaction transaction = new Transaction(m_Doc);
			bool result;
			try
			{
				transaction.Start("C");
				Category category2 = m_Doc.Settings.Categories.NewSubcategory(category, text2);
				if (text2.IndexOf(text) != -1)
				{
					category2.LineColor = lineColor;
					category2.SetLineWeight(num, (Autodesk.Revit.DB.GraphicsStyleType)1);
				}
				transaction.Commit();
				result = true;
			}
			catch (Exception)
			{
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
				result = false;
			}
			return result;
		}

		public List<List<Curve>> GetAllCloseCurves(List<Curve> lst)
		{
			if (lst.Count < 6)
			{
				return new List<List<Curve>>
				{
					lst
				};
			}
			List<double> arrayByAllCurves = this.GetArrayByAllCurves(lst);
			double[] arrayByLis = this.GetArrayByLis(arrayByAllCurves);
			List<double> allPointValue = new List<double>();
			List<int> allCloseZones = new List<int>();
            //Utils.GetMinCloseArray(arrayByLis, 0.01, ref allPointValue, ref allCloseZones);
			return this.GetAllCloseCurves(allPointValue, allCloseZones);
		}

		public static List<Curve> GetRemoveLittleLine(Autodesk.Revit.DB.Document doc, List<Curve> lstCurve, double disTemp)
		{
			List<Curve> list = new List<Curve>();
			double num = disTemp / 304.8;
			int num2 = 0;
			foreach (Curve curve in lstCurve)
			{
				XYZ endPoint = curve.GetEndPoint(0);
				XYZ endPoint2 = curve.GetEndPoint(1);
				if (endPoint.DistanceTo(endPoint2) > num)
				{
					list.Add(curve);
				}
				else
				{
					num2++;
				}
			}
			if (num2 == lstCurve.Count)
			{
				return null;
			}
			if (list.Count == 0)
			{
				return lstCurve;
			}
			List<XYZ> list2 = new List<XYZ>();
			for (int i = 0; i < list.Count; i++)
			{
				YJKLine hyline = new YJKLine(list[i] as Line);
				YJKLine hyline2;
				if (i == list.Count - 1)
				{
					hyline2 = new YJKLine(list[0] as Line);
				}
				else
				{
					hyline2 = new YJKLine(list[i + 1] as Line);
				}
				if (hyline.IsParallel(hyline2.Line) && hyline.GetDistance(hyline2.Line) < 0.1)
				{
					list2.Add(hyline.StartPoint);
					list2.Add(hyline.EndPoint);
					list2.Add(hyline2.StartPoint);
					list2.Add(hyline2.EndPoint);
				}
				else if (!hyline.IsParallel(hyline2.Line))
				{
					XYZ xyz = hyline.IntersectionPoint(hyline2.Line, true);
					list2.Add(hyline.StartPoint);
					list2.Add(hyline.EndPoint);
					if (xyz != null)
					{
						list2.Add(xyz);
					}
					list2.Add(hyline2.StartPoint);
					list2.Add(hyline2.EndPoint);
				}
			}
			List<XYZ> list3 = GroundStorehouseNozzle.CompressPointForCurve(list2, false);
			List<Curve> list4 = new List<Curve>();
			for (int j = 0; j < list3.Count; j++)
			{
				if (j == list3.Count - 1)
				{
					Curve item = Line.CreateBound(list3[list3.Count - 1], list3[0]);
					list4.Add(item);
				}
				else
				{
					Curve item2 = Line.CreateBound(list3[j], list3[j + 1]);
					list4.Add(item2);
				}
			}
			return list4;
		}

		public static List<XYZ> CompressPointForCurve(List<XYZ> arPt, bool blAdd = false)
		{
			if (arPt.Count < 2)
			{
				return arPt;
			}
			arPt.Remove(null);
			List<XYZ> list = new List<XYZ>();
			for (int i = 0; i < arPt.Count; i++)
			{
				bool flag = false;
				for (int j = 0; j < arPt.Count; j++)
				{
					if (i != j && arPt[j].DistanceTo(arPt[i]) < 0.01 && GroundStorehouseNozzle.GetPointBool(list, arPt[i]))
					{
						if (!blAdd)
						{
							list.Add(arPt[i]);
						}
						flag = true;
						break;
					}
				}
				if (!flag && GroundStorehouseNozzle.GetPointBool(list, arPt[i]))
				{
					list.Add(arPt[i]);
				}
			}
			return list;
		}

		private static bool GetPointBool(List<XYZ> lstPoint, XYZ p)
		{
			using (List<XYZ>.Enumerator enumerator = lstPoint.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.DistanceTo(p) < 0.1)
					{
						return false;
					}
				}
			}
			return true;
		}

		public static List<Element> GetRectElement(List<Curve> lstCurve, List<Element> lstElem)
		{
			List<Element> list = new List<Element>();
			foreach (Element element in lstElem)
			{
				XYZ point = (element.Location as LocationPoint).Point;
				if (XYZUtilityMethod.PointInPloygon(lstCurve, new XYZ(point.X, point.Y, 0.0)) == 1)
				{
					list.Add(element);
				}
			}
			return list;
		}

		public static double GetSetHeight(CurveLoop curveLoop, Autodesk.Revit.DB.Document doc)
		{
			double num = 22.965879265091864;
			if (curveLoop == null)
			{
				return 0.0;
			}
			double num2 = double.MaxValue;
			bool flag = false;
			List<CurveLoop> list = new List<CurveLoop>();
			list.Add(curveLoop);
			Solid solid = null;
			try
			{
				solid = GeometryCreationUtilities.CreateExtrusionGeometry(list, XYZ.BasisZ, num);
			}
			catch (Exception)
			{
			}
			ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
			ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(solid);
			LogicalAndFilter logicalAndFilter = new LogicalAndFilter(elementCategoryFilter, elementIntersectsSolidFilter);
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.WhereElementIsNotElementType();
			List<Element> list2 = filteredElementCollector.WherePasses(logicalAndFilter).ToElements().ToList<Element>();
			solid.Dispose();
			filteredElementCollector.Dispose();
			foreach (Element element in list2)
			{
				if (element is Floor)
				{
					double eleParamDoubleValue = GroundStorehouseNozzle.GetEleParamDoubleValue(element as Floor, "底部高程");
					if (eleParamDoubleValue < num2)
					{
						num2 = eleParamDoubleValue;
						flag = true;
					}
				}
			}
			if (!flag)
			{
				double num3 = double.MinValue;
				foreach (Curve curve in curveLoop)
				{
					XYZ hyendPoint = curve.GetEndPoint(0);
					if (num3 < hyendPoint.Z)
					{
						num3 = hyendPoint.Z;
					}
				}
				num2 = num3 + num;
			}
			GroundStorehouseNozzle.ReleaseFilers(new List<ElementFilter>
			{
				elementCategoryFilter,
				elementIntersectsSolidFilter,
				logicalAndFilter
			});
			return num2;
		}

		public static void ReleaseFilers(List<ElementFilter> arFilter)
		{
			if (arFilter.Count < 1)
			{
				return;
			}
			foreach (ElementFilter elementFilter in arFilter)
			{
				elementFilter.Dispose();
			}
			GC.Collect();
		}

		public static double GetEleParamDoubleValue(Element ele, string strParamName)
		{
			return ele.GetParameter(strParamName).AsDouble();
		}

		public static void FilterSplitArea(TextNoteOptions note, Autodesk.Revit.DB.Document doc, List<List<Curve>> allClosedCurves, out List<List<Curve>> rectRegions, out List<List<Curve>> notRectRegions)
		{
			rectRegions = new List<List<Curve>>();
			notRectRegions = new List<List<Curve>>();
			foreach (List<Curve> list in allClosedCurves)
			{
				if (list.Count != 0)
				{
					try
					{
						List<Curve> lstLine = list;
						bool flag = false;
						List<Curve> list2 = GroundStorehouseNozzle.MergeCurve(GroundStorehouseNozzle.SortListCurve(lstLine, out flag));
						if (GroundStorehouseNozzle.GetBlRect(list2))
						{
							rectRegions.Add(list2);
						}
						else
						{
							notRectRegions.Add(list);
						}
					}
					catch
					{
					}
				}
			}
		}

		public static bool IsNozzleInRoom(Element elem, Autodesk.Revit.DB.Document doc)
		{
			BoundingBoxXYZ boundingBoxXYZ = elem.get_BoundingBox(doc.ActiveView);
			List<Element> elementList = GroundStorehouseNozzle.GetElementList(boundingBoxXYZ.Max, boundingBoxXYZ.Min, (Autodesk.Revit.DB.BuiltInCategory)(-2008099), doc);
			if (elementList != null && elementList.Count != 0)
			{
				List<Curve> spaceOrRoomBoundaryCurve = YJKRevitTools.GetSpaceOrRoomBoundaryCurve(elem);
				foreach (Element element in elementList)
				{
					XYZ xyz = (element.Location as LocationPoint).Point;
					xyz = GroundStorehouseNozzle.SetZValue(xyz, 0.0);
					if (GroundStorehouseNozzle.PointInPloygon(spaceOrRoomBoundaryCurve, xyz) == 1 || GroundStorehouseNozzle.PointInPloygon(spaceOrRoomBoundaryCurve, xyz) == 0)
					{
						return true;
					}
				}
				return false;
			}
			return false;
		}

		public static List<Element> GetElementList(XYZ point1, XYZ point2, BuiltInCategory category, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(RevitAPIUIOperate.GetViewRange2(doc.ActiveView, false), point1, point2));
			foreach (Element item in new FilteredElementCollector(doc).OfCategory(category).WherePasses(boundingBoxIntersectsFilter).ToElements())
			{
				list.Add(item);
			}
			IEnumerable<Document> linkDocuments = doc.GetLinkDocuments();
			if (linkDocuments == null)
			{
				return list;
			}
			foreach (Autodesk.Revit.DB.Document document in linkDocuments)
			{
				if (document != null)
				{
					List<Element> elementFormDoc = GroundStorehouseNozzle.GetElementFormDoc(document, boundingBoxIntersectsFilter, category);
					list.AddRange(elementFormDoc);
				}
			}
			return list;
		}

		public static List<Element> GetElementFormDoc(Autodesk.Revit.DB.Document doc, BoundingBoxIntersectsFilter filter, BuiltInCategory category)
		{
			new List<Element>();
			new List<Element>();
			return new FilteredElementCollector(doc).OfCategory(category).WherePasses(filter).ToElements().ToList<Element>();
		}

		public static List<List<Curve>> MergeRectRegions(Autodesk.Revit.DB.Document doc, List<List<Curve>> lstRoomRegion)
		{
			new List<List<Curve>>();
			TextNoteOptions textNoteOptions = new TextNoteOptions();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(TextNoteType));
			FilteredElementIterator elementIterator = filteredElementCollector.GetElementIterator();
			elementIterator.Reset();
			TextNoteType textNoteType = elementIterator.Current as TextNoteType;
			textNoteOptions.TypeId = textNoteType.Id;
			double num = 7.8740157480314954;
			List<List<Curve>> list = new List<List<Curve>>();
			List<List<Curve>> list2 = new List<List<Curve>>();
			List<List<Curve>> list3 = new List<List<Curve>>();
			int num2 = 0;
			foreach (List<Curve> list4 in lstRoomRegion)
			{
				num2++;
				List<Curve> list5 = list4;
				if (GroundStorehouseNozzle.GetBlRect(list5))
				{
					bool flag = false;
					foreach (Curve curve in list5)
					{
						if (curve.GetEndPoint(0).DistanceTo(curve.GetEndPoint(1)) <= num)
						{
							if (GroundStorehouseNozzle.GetBlAddListList(list, list4, false))
							{
								list.Add(list4);
							}
							flag = true;
							break;
						}
					}
					if (!flag && GroundStorehouseNozzle.GetBlAddListList(list2, list4, false))
					{
						list2.Add(list4);
					}
				}
				else
				{
					list3.Add(list4);
				}
			}
			if (list.Count == 0)
			{
				return list2;
			}
			return GroundStorehouseNozzle.MergeArea(list, list2, num);
		}

		private static List<List<Curve>> MergeArea(List<List<Curve>> lstSmall, List<List<Curve>> lstBig, double disTemp)
		{
			if (lstSmall.Count == 0)
			{
				return lstBig;
			}
			List<Curve> list = lstSmall.First<List<Curve>>();
			List<Curve> list2 = new List<Curve>();
			List<Curve> list3 = new List<Curve>();
			list2 = GroundStorehouseNozzle.MergeList(lstSmall, lstBig, disTemp, ref list3);
			if (list2 == null || list2.Count == 0)
			{
				lstBig.Add(list);
				return GroundStorehouseNozzle.MergeArea(lstSmall, lstBig, disTemp);
			}
			List<Curve> list4 = new List<Curve>();
			list4.AddRange(list);
			list4.AddRange(list2);
			if (list3 != null && list3.Count != 0)
			{
				list4.AddRange(list3);
				GroundStorehouseNozzle.RemoveRepeatCurves(ref list4);
			}
			else
			{
				GroundStorehouseNozzle.RemoveRepeatCurves(ref list4);
			}
			bool flag = false;
			List<Curve> list5 = GroundStorehouseNozzle.MergeCurve(GroundStorehouseNozzle.SortListCurves(list4, out flag));
			if ((list.Count == 6 && list2.Count == 4 && list5.Count != 4) || (list.Count == 4 && list2.Count == 6 && list5.Count != 4))
			{
				lstBig.Add(list);
				return GroundStorehouseNozzle.MergeArea(lstSmall, lstBig, disTemp);
			}
			if (!GroundStorehouseNozzle.GetBlAddListList(lstSmall, list2, false))
			{
				lstSmall.Remove(list2);
			}
			else
			{
				lstBig.Remove(list2);
			}
			List<List<Curve>> list6 = new List<List<Curve>>();
			bool flag2 = false;
			foreach (Curve curve in list5)
			{
				if (curve.GetEndPoint(0).DistanceTo(curve.GetEndPoint(1)) <= disTemp)
				{
					if (GroundStorehouseNozzle.GetBlAddListList(list6, list5, false))
					{
						list6.Add(list5);
					}
					flag2 = true;
					break;
				}
			}
			list6.AddRange(lstSmall);
			if (!flag2 && GroundStorehouseNozzle.GetBlAddListList(lstBig, list5, false))
			{
				lstBig.Add(list5);
			}
			return GroundStorehouseNozzle.MergeArea(list6, lstBig, disTemp);
		}

		private static List<Curve> MergeList(List<List<Curve>> lstSmall, List<List<Curve>> lstBig, double disTemp, ref List<Curve> curve)
		{
			List<Curve> list = lstSmall.First<List<Curve>>();
			lstSmall.Remove(list);
			List<Curve> list2 = GroundStorehouseNozzle.SortCuves(list).ToList<Curve>();
			List<Curve> result = new List<Curve>();
			List<Curve> list3 = new List<Curve>();
			YJKLine hyline = new YJKLine(list2[0].GetEndPoint(0), list2[0].GetEndPoint(1));
			foreach (Curve curve2 in list2)
			{
				if (hyline.IsVertical(curve2 as Line) && hyline.IntersectionPoint(curve2 as Line) != null)
				{
					list3.Add(curve2);
				}
			}
			if (list3.Count == 2)
			{
				List<List<Curve>> list4 = new List<List<Curve>>();
				list4.AddRange(lstSmall);
				list4.AddRange(lstBig);
				if (list3[0].Length < list3[1].Length)
				{
					result = GroundStorehouseNozzle.ContainCurve(list3[0], list3[1], list4, ref curve);
				}
				else
				{
					result = GroundStorehouseNozzle.ContainCurve(list3[1], list3[0], list4, ref curve);
				}
			}
			return result;
		}

		private static List<Curve> ContainCurve(Curve curve1, Curve curve2, List<List<Curve>> allCurve, ref List<Curve> curve)
		{
			YJKLine hyline = new YJKLine(curve1.GetEndPoint(0), curve1.GetEndPoint(1));
			YJKLine hyline2 = new YJKLine(curve2.GetEndPoint(0), curve2.GetEndPoint(1));
			foreach (List<Curve> list in allCurve)
			{
				foreach (Curve curve3 in list)
				{
					YJKLine hyline3 = new YJKLine(curve3.GetEndPoint(0), curve3.GetEndPoint(1));
					if (hyline.IsParallel(hyline3.Line) && ((hyline.StartPoint.IsAlmostEqualTo(hyline3.StartPoint, 0.0001) && hyline.EndPoint.IsAlmostEqualTo(hyline3.EndPoint, 0.0001)) || (hyline.EndPoint.IsAlmostEqualTo(hyline3.StartPoint, 0.0001) && hyline.StartPoint.IsAlmostEqualTo(hyline3.EndPoint, 0.0001))))
					{
						return list;
					}
				}
			}
			foreach (List<Curve> list2 in allCurve)
			{
				foreach (Curve curve4 in list2)
				{
					YJKLine hyline4 = new YJKLine(curve4.GetEndPoint(0), curve4.GetEndPoint(1));
					if (hyline.IsParallel(hyline4.Line) && ((hyline2.StartPoint.IsAlmostEqualTo(hyline4.StartPoint, 0.0001) && hyline2.EndPoint.IsAlmostEqualTo(hyline4.EndPoint, 0.0001)) || (hyline2.EndPoint.IsAlmostEqualTo(hyline4.StartPoint, 0.0001) && hyline2.StartPoint.IsAlmostEqualTo(hyline4.EndPoint, 0.0001))))
					{
						return list2;
					}
				}
			}
			foreach (List<Curve> list3 in allCurve)
			{
				foreach (Curve curve5 in list3)
				{
					YJKLine hyline5 = new YJKLine(curve5.GetEndPoint(0), curve5.GetEndPoint(1));
					if (hyline.IsParallel(hyline5.Line) && ((hyline.IsPointOnLine(hyline5.StartPoint) && hyline.IsPointOnLine(hyline5.EndPoint)) || (hyline5.IsPointOnLine(hyline.StartPoint) && hyline5.IsPointOnLine(hyline.EndPoint))))
					{
						curve = GroundStorehouseNozzle.GetSplitCurve(hyline, hyline5);
						return list3;
					}
				}
			}
			foreach (List<Curve> list4 in allCurve)
			{
				foreach (Curve curve6 in list4)
				{
					YJKLine hyline6 = new YJKLine(curve6.GetEndPoint(0), curve6.GetEndPoint(1));
					if (hyline.IsParallel(hyline6.Line) && ((hyline2.IsPointOnLine(hyline6.StartPoint) && hyline2.IsPointOnLine(hyline6.EndPoint)) || (hyline6.IsPointOnLine(hyline2.StartPoint) && hyline6.IsPointOnLine(hyline2.EndPoint))))
					{
						curve = GroundStorehouseNozzle.GetSplitCurve(hyline2, hyline6);
						return list4;
					}
				}
			}
			return null;
		}

		private static List<Curve> GetSplitCurve(YJKLine hyline1, YJKLine hyline2)
		{
			List<Curve> list = new List<Curve>();
			if (hyline2.IsPointOnLine(hyline1.StartPoint) && hyline2.IsPointOnLine(hyline1.EndPoint))
			{
				YJKLine hyline3 = hyline1;
				hyline1 = hyline2;
				hyline2 = hyline3;
			}
			list.Add(hyline2.Line);
			XYZ xyz = (hyline1.StartPoint.DistanceTo(hyline2.StartPoint) < hyline1.StartPoint.DistanceTo(hyline2.EndPoint)) ? hyline2.StartPoint : hyline2.EndPoint;
			XYZ xyz2 = (hyline1.EndPoint.DistanceTo(hyline2.StartPoint) < hyline1.EndPoint.DistanceTo(hyline2.EndPoint)) ? hyline2.StartPoint : hyline2.EndPoint;
			if (!hyline1.StartPoint.IsAlmostEqualTo(xyz, 0.0001))
			{
				Line item = Line.CreateBound(hyline1.StartPoint, xyz);
				list.Add(item);
			}
			if (!hyline1.EndPoint.IsAlmostEqualTo(xyz2, 0.0001))
			{
				Line item2 = Line.CreateBound(hyline1.EndPoint, xyz2);
				list.Add(item2);
			}
			list.Add(hyline1.Line);
			return list;
		}

		private static List<List<Curve>> GetListListCurveSmall(List<List<Curve>> lstSmall)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			List<List<Curve>> list2 = new List<List<Curve>>();
			List<List<Curve>> list3 = new List<List<Curve>>();
			bool flag = false;
			foreach (List<Curve> list4 in lstSmall)
			{
				foreach (List<Curve> list5 in lstSmall)
				{
					if (list4 != list5 && GroundStorehouseNozzle.IsIntersect(list4, list5))
					{
						if (GroundStorehouseNozzle.GetBlAddListList(list2, list4, false))
						{
							list2.Add(list4);
						}
						if (GroundStorehouseNozzle.GetBlAddListList(list2, list5, false))
						{
							list2.Add(list5);
						}
						List<Curve> list6 = new List<Curve>();
						list6.AddRange(list4);
						list6.AddRange(list5);
						GroundStorehouseNozzle.RemoveRepeatCurves(ref list6);
						if (GroundStorehouseNozzle.GetBlAddListList(list, list6, false))
						{
							list.Add(list6);
						}
						flag = true;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
			if (!flag)
			{
				return lstSmall;
			}
			foreach (List<Curve> list7 in lstSmall)
			{
				if (GroundStorehouseNozzle.GetBlAddListList(list2, list7, false))
				{
					list3.Add(list7);
				}
			}
			list3.AddRange(list);
			return GroundStorehouseNozzle.GetListListCurveSmall(list3);
		}

		public static List<List<Curve>> MergeAbnormityRoom(Autodesk.Revit.DB.Document doc, List<List<Curve>> lstAbnormityRoom, out List<List<Curve>> lstAbnormityCurve)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			List<List<Curve>> list2 = new List<List<Curve>>();
			lstAbnormityCurve = new List<List<Curve>>();
			try
			{
				foreach (List<Curve> list3 in lstAbnormityRoom)
				{
					bool flag = false;
					foreach (List<Curve> list4 in lstAbnormityRoom)
					{
						try
						{
							if (list3 != list4)
							{
								if (GroundStorehouseNozzle.IsIntersect(list3, list4))
								{
									List<Curve> list5 = new List<Curve>();
									list5.AddRange(list3);
									list5.AddRange(list4);
									GroundStorehouseNozzle.RemoveRepeatCurves(ref list5);
									bool flag2 = false;
									List<Curve> list6 = GroundStorehouseNozzle.MergeCurve(GroundStorehouseNozzle.SortListCurve(list5, out flag2));
									if (GroundStorehouseNozzle.GetBlRect(list6))
									{
										list.Add(list3);
										list.Add(list4);
										if (!GroundStorehouseNozzle.GetBlAddListList(lstAbnormityCurve, list3, false))
										{
											lstAbnormityCurve.Remove(list3);
										}
										if (!GroundStorehouseNozzle.GetBlAddListList(lstAbnormityCurve, list4, false))
										{
											lstAbnormityCurve.Remove(list4);
										}
										if (GroundStorehouseNozzle.GetBlAddListList(list2, list6, true))
										{
											list2.Add(list6);
											flag = true;
											break;
										}
									}
								}
							}
						}
						catch (Exception ex)
						{
							ex.ToString();
						}
					}
					if (!flag && GroundStorehouseNozzle.GetBlAddListList(list, list3, false))
					{
						lstAbnormityCurve.Add(list3);
					}
				}
			}
			catch (Exception ex2)
			{
				ex2.ToString();
			}
			return list2;
		}

		public static bool GetBlAddListList(List<List<Curve>> lstlstCurve, List<Curve> TempCurve, bool bl = false)
		{
			foreach (List<Curve> list in lstlstCurve)
			{
				if (bl)
				{
					int num = 0;
					if (list.Count == TempCurve.Count)
					{
						for (int i = 0; i < list.Count; i++)
						{
							XYZ xyz = GroundStorehouseNozzle.SetZValue(list[i].GetEndPoint(0), 0.0);
							XYZ xyz2 = GroundStorehouseNozzle.SetZValue(list[i].GetEndPoint(1), 0.0);
							YJKLine hyline = new YJKLine(Line.CreateBound(xyz, xyz2));
							double num2 = hyline.StartPoint.DistanceTo(hyline.EndPoint);
							for (int j = 0; j < TempCurve.Count; j++)
							{
								XYZ xyz3 = GroundStorehouseNozzle.SetZValue(TempCurve[j].GetEndPoint(0), 0.0);
								XYZ xyz4 = GroundStorehouseNozzle.SetZValue(TempCurve[j].GetEndPoint(1), 0.0);
								YJKLine hyline2 = new YJKLine(Line.CreateBound(xyz3, xyz4));
								double num3 = hyline2.StartPoint.DistanceTo(hyline2.EndPoint);
								if (num2 == num3 && hyline2.IsParallel(hyline.Line) && hyline2.IsLineOnLine(hyline.Line))
								{
									num++;
								}
							}
						}
						if (num == list.Count)
						{
							return false;
						}
					}
				}
				else if (list.Count == TempCurve.Count)
				{
					int num4 = 0;
					for (int k = 0; k < list.Count; k++)
					{
						XYZ xyz5 = GroundStorehouseNozzle.SetZValue(list[k].GetEndPoint(0), 0.0);
						XYZ xyz6 = GroundStorehouseNozzle.SetZValue(TempCurve[k].GetEndPoint(0), 0.0);
						XYZ xyz7 = GroundStorehouseNozzle.SetZValue(list[k].GetEndPoint(1), 0.0);
						XYZ xyz8 = GroundStorehouseNozzle.SetZValue(TempCurve[k].GetEndPoint(1), 0.0);
						if (xyz5.DistanceTo(xyz6) < 0.0001 && xyz7.DistanceTo(xyz8) < 0.0001)
						{
							num4++;
						}
					}
					if (num4 == list.Count)
					{
						return false;
					}
				}
			}
			return true;
		}

		private static XYZ SetZValue(XYZ point, double zValue)
		{
			return new XYZ(point.X, point.Y, zValue);
		}

		public static bool GetBlRect(List<Curve> lstCurve)
		{
			return lstCurve.Count == 4 && ((GroundStorehouseNozzle.IsPipeParallel(lstCurve[0], lstCurve[1]) && GroundStorehouseNozzle.IsPipeParallel(lstCurve[2], lstCurve[3]) && (GroundStorehouseNozzle.GetSinValue(lstCurve[0], lstCurve[2]) == 90.0 || GroundStorehouseNozzle.GetSinValue(lstCurve[0], lstCurve[3]) == 90.0)) || (GroundStorehouseNozzle.IsPipeParallel(lstCurve[0], lstCurve[2]) && GroundStorehouseNozzle.IsPipeParallel(lstCurve[1], lstCurve[3]) && (GroundStorehouseNozzle.GetSinValue(lstCurve[0], lstCurve[1]) == 90.0 || GroundStorehouseNozzle.GetSinValue(lstCurve[0], lstCurve[3]) == 90.0)) || (GroundStorehouseNozzle.IsPipeParallel(lstCurve[0], lstCurve[3]) && GroundStorehouseNozzle.IsPipeParallel(lstCurve[1], lstCurve[2]) && (GroundStorehouseNozzle.GetSinValue(lstCurve[0], lstCurve[1]) == 90.0 || GroundStorehouseNozzle.GetSinValue(lstCurve[0], lstCurve[2]) == 90.0)));
		}

		private static double GetSinValue(Curve curve1, Curve curve2)
		{
			Line line = curve1 as Line;
			Line line2 = curve2 as Line;
			double num = Math.Asin(Math.Sin(line.Direction.AngleTo(line2.Direction))) * 180.0 / Math.PI;
			if (Math.Abs(num - 90.0) < 2.0)
			{
				num = 90.0;
			}
			return num;
		}

		public static void RemoveRepeatCurves(ref List<Curve> curves)
		{
			List<Curve> list = new List<Curve>();
			for (int i = 0; i < curves.Count; i++)
			{
				bool flag = false;
				for (int j = 0; j < curves.Count; j++)
				{
					if (i != j)
					{
						XYZ endPoint = curves[i].GetEndPoint(0);
						XYZ endPoint2 = curves[i].GetEndPoint(1);
						XYZ endPoint3 = curves[j].GetEndPoint(0);
						XYZ endPoint4 = curves[j].GetEndPoint(1);
						if (Math.Abs(curves[i].Length - curves[j].Length) < 1E-05 && ((endPoint.DistanceTo(endPoint3) < 0.0001 && endPoint2.DistanceTo(endPoint4) < 0.0001) || (endPoint.DistanceTo(endPoint4) < 0.0001 && endPoint2.DistanceTo(endPoint3) < 0.0001)))
						{
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					list.Add(curves[i]);
				}
			}
			curves.Clear();
			curves.AddRange(list);
		}

		private static bool IsIntersect(List<Curve> eachColumnCurves, List<Curve> roomWallSideCurves)
		{
			foreach (Curve curve in eachColumnCurves)
			{
				foreach (Curve curve2 in roomWallSideCurves)
				{
					curve.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(0));
					curve.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(1));
					curve.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(1));
					curve.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(0));
					if ((curve.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(0)) < 0.0001 && curve.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(1)) < 0.0001) || (curve.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(0)) < 0.0001 && curve.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(1)) < 0.0001))
					{
						return true;
					}
				}
			}
			return false;
		}

		public static List<List<Curve>> GetListList(Autodesk.Revit.DB.Document doc, List<Room> lstRoomRegion)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			TextNoteOptions textNoteOptions = new TextNoteOptions();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(TextNoteType));
			FilteredElementIterator elementIterator = filteredElementCollector.GetElementIterator();
			elementIterator.Reset();
			TextNoteType textNoteType = elementIterator.Current as TextNoteType;
			textNoteOptions.TypeId = textNoteType.Id;
			foreach (Room spaceOrRoom in lstRoomRegion)
			{
				List<Curve> spaceOrRoomBoundaryCurve = YJKRevitTools.GetSpaceOrRoomBoundaryCurve(spaceOrRoom);
				XYZ xyz = XYZ.BasisX * 77000.0 / 304.8;
				foreach (Curve curve in spaceOrRoomBoundaryCurve)
				{
					XYZ xyz2 = YJKRevitTools.SetZToZero(curve.GetEndPoint(0)).Add(xyz);
					XYZ ePoint = YJKRevitTools.SetZToZero(curve.GetEndPoint(1)).Add(xyz);
					YJKRevitTools.DrawDetailLine(doc, doc.ActiveView, xyz2, ePoint);
				}
				list.Add(spaceOrRoomBoundaryCurve);
			}
			return list;
		}

		public static List<List<Curve>> GetListList(List<Element> lstRoomRegion, ref List<Curve> outCurves)
		{
			List<Curve> spaceOrRoomBoundaryCurve = YJKRevitTools.GetSpaceOrRoomBoundaryCurve(lstRoomRegion.First<Element>());
			if (spaceOrRoomBoundaryCurve.Count == 0)
			{
				return null;
			}
			GroundStorehouseNozzle groundStorehouseNozzle = new GroundStorehouseNozzle();
			double[] inPnts = groundStorehouseNozzle.GetArrayByAllCurves(spaceOrRoomBoundaryCurve).ToArray();
			List<double> allPointValue = new List<double>();
			List<int> allCloseZones = new List<int>();
            //Utils.GetMinCloseArray(inPnts, 0.01, ref allPointValue, ref allCloseZones);
			List<List<Curve>> allCloseCurves = groundStorehouseNozzle.GetAllCloseCurves(allPointValue, allCloseZones);
			outCurves = GroundStorehouseNozzle.GetOutCurves(spaceOrRoomBoundaryCurve, allCloseCurves);
			return allCloseCurves;
		}

		private static List<Curve> GetOutCurves(List<Curve> lstTempMerge, List<List<Curve>> lstlstTempMerge)
		{
			List<Curve> result = new List<Curve>();
			List<XYZ> list = new List<XYZ>();
			foreach (Curve curve in lstTempMerge)
			{
				list.Add(curve.GetEndPoint(0));
				list.Add(curve.GetEndPoint(1));
			}
			XYZ leftTopPoint = GroundStorehouseNozzle.GetLeftTopPoint(list);
			Curve curve2 = lstTempMerge[0];
			foreach (Curve curve3 in lstTempMerge)
			{
				if (curve3.GetEndPoint(0).DistanceTo(leftTopPoint) < 0.001)
				{
					curve2 = curve3;
					break;
				}
			}
			foreach (List<Curve> list2 in lstlstTempMerge)
			{
				foreach (Curve curve4 in list2)
				{
					if ((curve4.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(0)) < 0.001 && curve4.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(1)) < 0.001) || (curve4.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(1)) < 0.001 && curve4.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(0)) < 0.001))
					{
						result = list2;
						break;
					}
				}
			}
			return result;
		}

		public static List<Curve> GetCzCurve(List<Curve> lstAll, List<Curve> lst)
		{
			List<Curve> list = new List<Curve>();
			if (lstAll.Count <= lst.Count)
			{
				return null;
			}
			foreach (Curve curve in lstAll)
			{
				bool flag = false;
				foreach (Curve curve2 in lst)
				{
					if (curve.GetEndPoint(0).DistanceTo(curve2.GetEndPoint(0)) < 0.1 && curve.GetEndPoint(1).DistanceTo(curve2.GetEndPoint(1)) < 0.1)
					{
						flag = true;
					}
				}
				if (!flag && curve is Line)
				{
					list.Add(curve);
				}
			}
			return list;
		}

		public static List<Curve> MergeCurve(List<Curve> lstLine)
		{
			if (lstLine.Count == 4)
			{
				return lstLine;
			}
			List<Curve> list = new List<Curve>();
			if (lstLine.Count < 3)
			{
				return list;
			}
			list.Add(lstLine[0]);
			foreach (Curve curve in lstLine)
			{
				bool flag = false;
				foreach (Curve curve2 in lstLine)
				{
					if (!list.Contains(curve2))
					{
						Line line = list.Last<Curve>() as Line;
						YJKLine hyline = new YJKLine(line.GetEndPoint(0), line.GetEndPoint(1));
						XYZ endPoint = (curve2 as Line).GetEndPoint(0);
						XYZ endPoint2 = (curve2 as Line).GetEndPoint(1);
						if ((!hyline.IsPointOnLine(endPoint) || !hyline.IsPointOnLine(endPoint2)) && GroundStorehouseNozzle.IsPipeParallel(list.Last<Curve>(), curve2))
						{
							List<XYZ> list2 = GroundStorehouseNozzle.CompressPointForCurve(new List<XYZ>
							{
								list.Last<Curve>().GetEndPoint(0),
								list.Last<Curve>().GetEndPoint(1),
								curve2.GetEndPoint(0),
								curve2.GetEndPoint(1)
							}, true);
							if (list2.Count == 2)
							{
								Curve item = Line.CreateBound(list2[0], list2[1]);
								list.Remove(list.Last<Curve>());
								list.Add(item);
								flag = true;
								break;
							}
						}
					}
				}
				if (!flag && !list.Contains(curve))
				{
					bool flag2 = false;
					foreach (Curve curve3 in list)
					{
						YJKLine hyline2 = new YJKLine(curve3.GetEndPoint(0), curve3.GetEndPoint(1));
						XYZ endPoint3 = (curve as Line).GetEndPoint(0);
						XYZ endPoint4 = (curve as Line).GetEndPoint(1);
						if (hyline2.IsPointOnLine(endPoint3) && hyline2.IsPointOnLine(endPoint4))
						{
							flag2 = true;
							break;
						}
					}
					if (!flag2 && GroundStorehouseNozzle.CompressPointForCurve(new List<XYZ>
					{
						list.Last<Curve>().GetEndPoint(0),
						list.Last<Curve>().GetEndPoint(1),
						curve.GetEndPoint(0),
						curve.GetEndPoint(1)
					}, false).Count == 3)
					{
						list.Add(curve);
					}
				}
			}
			List<XYZ> list3 = GroundStorehouseNozzle.CompressPointForCurve(new List<XYZ>
			{
				list.Last<Curve>().GetEndPoint(0),
				list.Last<Curve>().GetEndPoint(1),
				list.First<Curve>().GetEndPoint(0),
				list.First<Curve>().GetEndPoint(1)
			}, true);
			if (GroundStorehouseNozzle.IsPipeParallel(list.Last<Curve>(), list.First<Curve>()) && list3.Count == 2)
			{
				Curve item2 = Line.CreateBound(list3[0], list3[1]);
				list.Remove(list.Last<Curve>());
				list.Remove(list.First<Curve>());
				list.Insert(0, item2);
			}
			if (list3.Count == 4)
			{
				return lstLine;
			}
			return list;
		}

		public static bool IsPipeParallel(Curve curve1, Curve curve2)
		{
			Line line = curve1 as Line;
			Line line2 = curve2 as Line;
			return Math.Sin(line.Direction.AngleTo(line2.Direction)) < 0.01;
		}

		public static List<Curve> SortListCurve(List<Curve> lstLine, out bool bl)
		{
			List<Curve> list = new List<Curve>();
			List<XYZ> list2 = new List<XYZ>();
			foreach (Curve curve in lstLine)
			{
				list2.Add(curve.GetEndPoint(0));
				list2.Add(curve.GetEndPoint(1));
			}
			XYZ leftTopPoint = GroundStorehouseNozzle.GetLeftTopPoint(list2);
			List<XYZ> list3 = new List<XYZ>();
			list3.Add(leftTopPoint);
			foreach (Curve curve2 in lstLine)
			{
				foreach (Curve curve3 in lstLine)
				{
					curve3.GetEndPoint(0);
					curve3.GetEndPoint(1);
					list3.Last<XYZ>();
					if (curve3.GetEndPoint(0).DistanceTo(list3.Last<XYZ>()) < 0.1 && GroundStorehouseNozzle.GetListPointBool(list3, curve3.GetEndPoint(1)))
					{
						list3.Add(curve3.GetEndPoint(1));
						break;
					}
					if (curve3.GetEndPoint(1).DistanceTo(list3.Last<XYZ>()) < 0.1 && GroundStorehouseNozzle.GetListPointBool(list3, curve3.GetEndPoint(0)))
					{
						list3.Add(curve3.GetEndPoint(0));
						break;
					}
				}
			}
			for (int i = 0; i < list3.Count; i++)
			{
				if (i == list3.Count - 1)
				{
					if (list3.Last<XYZ>().DistanceTo(list3[0]) == 0.0)
					{
						list3.Remove(list3.Last<XYZ>());
						Curve item = Line.CreateBound(list3.Last<XYZ>(), list3[0]);
						list.Add(item);
					}
					else
					{
						Curve item2 = Line.CreateBound(list3.Last<XYZ>(), list3[0]);
						list.Add(item2);
					}
				}
				else if (list3[i].DistanceTo(list3[i + 1]) > 0.1)
				{
					Curve item3 = Line.CreateBound(list3[i], list3[i + 1]);
					list.Add(item3);
				}
			}
			if (list.Count == 4)
			{
				YJKLine hyline = new YJKLine(list[0] as Line);
				YJKLine hyline2 = new YJKLine(list[1] as Line);
				YJKLine hyline3 = new YJKLine(list[2] as Line);
				YJKLine hyline4 = new YJKLine(list[3] as Line);
				XYZ xyz = hyline.IntersectionPoint(hyline2.Line, true);
				XYZ xyz2 = hyline2.IntersectionPoint(hyline3.Line, true);
				XYZ xyz3 = hyline3.IntersectionPoint(hyline4.Line, true);
				XYZ xyz4 = hyline4.IntersectionPoint(hyline.Line, true);
				if (xyz != null && xyz2 != null && xyz3 != null && xyz4 != null)
				{
					list.Clear();
					list.Add(Line.CreateBound(xyz4, xyz));
					list.Add(Line.CreateBound(xyz, xyz2));
					list.Add(Line.CreateBound(xyz2, xyz3));
					list.Add(Line.CreateBound(xyz3, xyz4));
				}
			}
			if (list.Count == lstLine.Count)
			{
				bl = false;
			}
			else
			{
				bl = true;
			}
			return list;
		}

		public static List<Curve> SortListCurves(List<Curve> lstLine, out bool bl)
		{
			List<Curve> list = new List<Curve>();
			List<XYZ> list2 = new List<XYZ>();
			foreach (Curve curve in lstLine)
			{
				list2.Add(curve.GetEndPoint(0));
				list2.Add(curve.GetEndPoint(1));
			}
			XYZ leftTopPoint = GroundStorehouseNozzle.GetLeftTopPoint(list2);
			Curve curve2 = lstLine[0];
			foreach (Curve curve3 in lstLine)
			{
				if (curve3.GetEndPoint(0).DistanceTo(leftTopPoint) < 0.001)
				{
					curve2 = curve3;
					break;
				}
			}
			Curve curve4 = curve2;
			foreach (Curve curve5 in lstLine)
			{
				foreach (Curve curve6 in lstLine)
				{
					if (!list.Contains(curve6))
					{
						if (curve4.GetEndPoint(1).DistanceTo(curve6.GetEndPoint(0)) < 0.1 || curve4.GetEndPoint(1).DistanceTo(curve6.GetEndPoint(1)) < 0.1)
						{
							list.Add(curve6);
							curve4 = curve6;
							break;
						}
						if (curve4.GetEndPoint(0).DistanceTo(curve6.GetEndPoint(0)) < 0.1 || curve4.GetEndPoint(0).DistanceTo(curve6.GetEndPoint(1)) < 0.1)
						{
							list.Add(curve6);
							curve4 = curve6;
							break;
						}
					}
				}
				if (list.Count == lstLine.Count)
				{
					break;
				}
			}
			if (list.Count != lstLine.Count)
			{
				bl = true;
			}
			else
			{
				bl = false;
			}
			return list;
		}

		private static bool GetListPointBool(List<XYZ> points, XYZ point)
		{
			using (List<XYZ>.Enumerator enumerator = points.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.DistanceTo(point) < 0.01)
					{
						return false;
					}
				}
			}
			return true;
		}

		public static XYZ GetLeftTopPoint(List<XYZ> lstPoint)
		{
			XYZ xyz = lstPoint[0];
			foreach (XYZ xyz2 in lstPoint)
			{
				if (xyz2.Y > xyz.Y)
				{
					xyz = xyz2;
				}
			}
			foreach (XYZ xyz3 in lstPoint)
			{
				if (Math.Round(xyz3.Y, 2) == Math.Round(xyz.Y, 2) && xyz3.X < xyz.X)
				{
					xyz = xyz3;
				}
			}
			return xyz;
		}

		public List<Curve> RoomAndGridSegment(Autodesk.Revit.DB.Document doc, List<List<Curve>> lstlstIn, List<Curve> outCurves)
		{
			List<Grid> specifyElements = GroundStorehouseNozzle.GetSpecifyElements(doc);
			List<Curve> list = new List<Curve>();
			foreach (Grid grid in specifyElements)
			{
				Curve curve = grid.Curve;
				list.Add(curve);
			}
			list = this.GetValidGridCurves(doc, lstlstIn);
			return this.GetAllCurves(lstlstIn, list, outCurves, doc);
		}

		private List<Curve> GetValidGridCurves(Autodesk.Revit.DB.Document doc, List<List<Curve>> lstlst)
		{
			List<Grid> specifyElements = GroundStorehouseNozzle.GetSpecifyElements(doc);
			List<Curve> list = new List<Curve>();
			foreach (Grid grid in specifyElements)
			{
				Curve curve = grid.Curve;
				YJKLine hyline = new YJKLine(curve as Line);
				foreach (List<Curve> list2 in lstlst)
				{
					bool flag = false;
					foreach (Curve curve2 in list2)
					{
						if (hyline.IntersectionPoint(curve2 as Line) != null)
						{
							list.Add(curve);
							flag = true;
							break;
						}
					}
					if (flag)
					{
						break;
					}
				}
			}
			return list;
		}

		public static List<Grid> GetSpecifyElements(Autodesk.Revit.DB.Document doc)
		{
			Type typeFromHandle = typeof(Grid);
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeFromHandle);
			List<Grid> list = filteredElementCollector.Cast<Grid>().ToList<Grid>();
			List<Document> list2 = new List<Document>();
			foreach (LinkedDocument linkedDocument in doc.GetLinkedDocuments())
			{
				list2.Add(linkedDocument.Document);
			}
			foreach (Autodesk.Revit.DB.Document document in list2)
			{
				FilteredElementCollector filteredElementCollector2 = new FilteredElementCollector(document);
				filteredElementCollector2.OfCategory(BuiltInCategory.OST_Grids);
				foreach (Element element in filteredElementCollector2)
				{
					if (element is Grid)
					{
						list.Add(element as Grid);
					}
				}
			}
			return list;
		}

		public List<Curve> GetAllCurves(List<List<Curve>> lstlstInCurves, List<Curve> allGrids, List<Curve> outCurves, Autodesk.Revit.DB.Document doc)
		{
			List<Curve> list = new List<Curve>();
			List<Curve> list2 = new List<Curve>();
			foreach (List<Curve> list3 in lstlstInCurves)
			{
				foreach (Curve item in list3)
				{
					list2.Add(item);
				}
			}
			list2.AddRange(allGrids);
			list = this.GetAllSegmentCurves(list2, doc);
			List<Curve> list4 = this.FilterNoValidCurves(list, lstlstInCurves, outCurves);
			GroundStorehouseNozzle.RemoveRepeatCurves(ref list);
			foreach (Curve item2 in list4)
			{
				list.Remove(item2);
			}
			return list;
		}

		private List<Curve> FilterNoValidCurves(List<Curve> curves, List<List<Curve>> lstlstInCurves, List<Curve> outCurves)
		{
			return new List<Curve>();
		}

		private bool GetBoolCurve(List<Curve> outCurves, YJKLine hyLine)
		{
			foreach (Curve curve in outCurves)
			{
				YJKLine hyline = new YJKLine(curve as Line);
				if (hyline.IsXYParallel(hyLine.Line) && hyline.GetDistance(hyLine.Line) < 1.0)
				{
					return true;
				}
			}
			return false;
		}

		private List<XYZ> GetAllIntersectionPoints(List<Curve> allRoomLines, List<Curve> allLines)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (Curve curve in allLines)
			{
				YJKLine hyline = new YJKLine(curve as Line);
				foreach (Curve curve2 in allLines)
				{
					if (!hyline.IsParallel(curve2 as Line))
					{
						XYZ xyz = hyline.IntersectionPoint(curve2 as Line);
						if (xyz != null)
						{
							list.Add(xyz);
						}
					}
				}
			}
			return list;
		}

		private List<Curve> GetAllWallSegmentCurves(List<Curve> allWallCurves, List<Curve> allValidGridCurves, List<Curve> outWallCurves)
		{
			List<Curve> list = new List<Curve>();
			list.Clear();
			foreach (Curve curve in allWallCurves)
			{
				List<XYZ> list2 = new List<XYZ>();
				YJKLine hyLine = new YJKLine(curve as Line);
				List<Curve> collection = new List<Curve>();
				foreach (Curve curve2 in allValidGridCurves)
				{
					if (!new YJKLine(curve2 as Line).IsParallel(curve as Line))
					{
						XYZ xyz = hyLine.IntersectionPoint(curve2 as Line);
						if (xyz != null)
						{
							list2.Add(xyz);
						}
					}
				}
				if ((from s in list2
				where s.IsAlmostEqualTo(hyLine.StartPoint, 0.0001)
				select s).ToList<XYZ>().Count == 0 && GroundStorehouseNozzle.PointInPloygon(outWallCurves, hyLine.StartPoint) != 1)
				{
					list2.Add(hyLine.StartPoint);
				}
				if ((from s in list2
				where s.IsAlmostEqualTo(hyLine.EndPoint, 0.01)
				select s).ToList<XYZ>().Count == 0 && GroundStorehouseNozzle.PointInPloygon(outWallCurves, hyLine.EndPoint) != 1)
				{
					list2.Add(hyLine.EndPoint);
				}
				new List<XYZ>();
				if (list2.Count > 2)
				{
					list2 = this.GroupByPoints(list2, hyLine.StartPoint);
				}
				collection = this.GetDivisionCurves(list2);
				list.AddRange(collection);
			}
			return list;
		}

		private List<Curve> GetAllSegmentCurves(List<Curve> allCurves, Autodesk.Revit.DB.Document doc)
		{
			List<XYZ> list = new List<XYZ>();
			List<Curve> list2 = new List<Curve>();
			foreach (Curve curve in allCurves)
			{
				foreach (Curve curve2 in allCurves)
				{
					YJKLine hyItem = new YJKLine(curve as Line);
					new YJKLine(curve2 as Line);
					XYZ interPt = hyItem.IntersectionPoint(curve2 as Line);
					if ((from s in list
					where s.IsAlmostEqualTo(hyItem.StartPoint, 0.0001)
					select s).ToList<XYZ>().Count == 0 || (from s in list
					where s.IsAlmostEqualTo(hyItem.StartPoint, 0.0001)
					select s).ToList<XYZ>() == null)
					{
						list.Add(hyItem.StartPoint);
					}
					if ((from s in list
					where s.IsAlmostEqualTo(hyItem.EndPoint, 0.0001)
					select s).ToList<XYZ>().Count == 0 || (from s in list
					where s.IsAlmostEqualTo(hyItem.EndPoint, 0.0001)
					select s).ToList<XYZ>() == null)
					{
						list.Add(hyItem.EndPoint);
					}
					if (interPt != null && ((from s in list
					where s.IsAlmostEqualTo(interPt, 0.0001)
					select s).ToList<XYZ>().Count == 0 || (from s in list
					where s.IsAlmostEqualTo(interPt, 0.0001)
					select s).ToList<XYZ>() == null))
					{
						list.Add(interPt);
					}
				}
			}
			foreach (Curve curve3 in allCurves)
			{
				YJKLine hyLine = new YJKLine(curve3 as Line);
				List<XYZ> list3 = new List<XYZ>();
				foreach (XYZ xyz in list)
				{
					if (hyLine.IsPointOnLine(xyz))
					{
						list3.Add(xyz);
					}
				}
				if ((from s in list3
				where s.IsAlmostEqualTo(hyLine.StartPoint, 0.0001)
				select s).ToList<XYZ>().Count == 0 || (from s in list3
				where s.IsAlmostEqualTo(hyLine.StartPoint, 0.0001)
				select s).ToList<XYZ>() == null)
				{
					list3.Add(hyLine.StartPoint);
				}
				if ((from s in list3
				where s.IsAlmostEqualTo(hyLine.EndPoint, 0.0001)
				select s).ToList<XYZ>().Count == 0 || (from s in list3
				where s.IsAlmostEqualTo(hyLine.EndPoint, 0.0001)
				select s).ToList<XYZ>() == null)
				{
					list3.Add(hyLine.EndPoint);
				}
				list3 = this.GroupByPoints(list3, hyLine.StartPoint);
				List<Curve> divisionCurves = this.GetDivisionCurves(list3);
				list2.AddRange(divisionCurves);
			}
			return list2;
		}

		private List<Curve> GetAllGridSegmentCurves(List<Curve> allWallCurves, List<Curve> allValidGridCurves, List<Curve> outWallCurves)
		{
			new List<Curve>();
			List<Curve> list = new List<Curve>();
			list.AddRange(allWallCurves);
			list.AddRange(allValidGridCurves);
			return this.GetAllWallSegmentCurves(allValidGridCurves, list, outWallCurves);
		}

		private List<XYZ> GroupByPoints(List<XYZ> wallGridIntersect, XYZ point)
		{
			new List<Curve>();
			XYZ value = new XYZ();
			for (int i = 0; i < wallGridIntersect.Count - 1; i++)
			{
				for (int j = i + 1; j < wallGridIntersect.Count; j++)
				{
					if (wallGridIntersect[i].DistanceTo(point) > wallGridIntersect[j].DistanceTo(point))
					{
						value = wallGridIntersect[i];
						wallGridIntersect[i] = wallGridIntersect[j];
						wallGridIntersect[j] = value;
					}
				}
			}
			return wallGridIntersect;
		}

		private List<Curve> GetDivisionCurves(List<XYZ> allIntersects)
		{
			List<Curve> list = new List<Curve>();
			PointComparer comparer = new PointComparer();
			List<XYZ> list2 = allIntersects.Distinct(comparer).ToList<XYZ>();
			int num = 0;
			while (num < list2.Count - 1 && num + 1 <= list2.Count - 1)
			{
				if (!list2[num].IsAlmostEqualTo(list2[num + 1], 0.0001))
				{
					Line line = Line.CreateBound(list2[num], list2[num + 1]);
					new YJKLine(line);
					list.Add(line);
				}
				num++;
			}
			return list;
		}

		public List<Curve> GetValidGrid(Autodesk.Revit.DB.Document doc, List<Curve> outWallCurve, List<Element> allGrids)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (Curve curve in outWallCurve)
			{
				YJKLine hyline = new YJKLine(curve as Line);
				XYZ startPoint = hyline.StartPoint;
				XYZ endPoint = hyline.EndPoint;
				list.Add(startPoint);
				list.Add(endPoint);
			}
			XYZ min = new XYZ();
			XYZ min2 = new XYZ();
			GroundStorehouseNozzle.GetBoundaryPoint(list, out min, out min2);
			this.GetGridList(doc, new BoundingBoxXYZ
			{
				Min = min2,
                //Min = min
			}, ref allGrids);
			List<Curve> list2 = new List<Curve>();
			foreach (Element element in allGrids)
			{
				Curve curve2 = ((Grid)element).Curve;
				list2.Add(curve2);
			}
			return list2;
		}

		private BoundingBoxIntersectsFilter GetBoundingBoxFilter(BoundingBoxXYZ bounding)
		{
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			return new BoundingBoxIntersectsFilter(new Outline(bounding.Min - xyz, bounding.Max + xyz), false);
		}

		private void GetGridList(Autodesk.Revit.DB.Document doc, BoundingBoxXYZ bounding, ref List<Element> elements)
		{
			BoundingBoxIntersectsFilter boundingBoxFilter = this.GetBoundingBoxFilter(bounding);
			foreach (Element item in new FilteredElementCollector(doc).OfClass(typeof(Grid)).WherePasses(boundingBoxFilter).ToElements())
			{
				elements.Add(item);
			}
		}

		public static void GetBoundaryPoint(List<XYZ> lstPoint, out XYZ maxLeftTop, out XYZ minRightButtom)
		{
			maxLeftTop = new XYZ();
			minRightButtom = new XYZ();
			double x = lstPoint[0].X;
			double y = lstPoint[0].Y;
			double x2 = lstPoint[0].X;
			double y2 = lstPoint[0].Y;
			foreach (XYZ xyz in lstPoint)
			{
				if (xyz.Y > y)
				{
					y = xyz.Y;
				}
				if (xyz.Y < y2)
				{
					y2 = xyz.Y;
				}
				if (xyz.X > x)
				{
					x = xyz.X;
				}
				if (xyz.X < x2)
				{
					x2 = xyz.X;
				}
			}
			maxLeftTop = new XYZ(x2, y, 100.0);
			minRightButtom = new XYZ(x, y2, -100.0);
		}

		public static void GetAllPoints(ref List<XYZ> points, List<List<Curve>> lstlstCurve)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (XYZ xyz in points)
			{
				bool flag = false;
				for (int i = 0; i < lstlstCurve.Count - 1; i++)
				{
					if (GroundStorehouseNozzle.PointInPloygon(lstlstCurve[i], xyz) == 1)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					list.Add(xyz);
				}
			}
			List<XYZ> list2 = new List<XYZ>();
			foreach (XYZ xyz2 in list)
			{
				if (GroundStorehouseNozzle.PointInPloygon(lstlstCurve.Last<List<Curve>>(), xyz2) != -1)
				{
					list2.Add(xyz2);
				}
			}
			points.Clear();
			points = list2;
		}

		public static int PointInPloygon(List<Curve> lstCurves, XYZ pt)
		{
			return XYZUtilityMethod.PointInPloygon(lstCurves, pt);
		}

		public List<XYZ> AllSprinklerLayPoints(List<List<Curve>> mergeRooms, List<List<Curve>> lstNotMergeArea)
		{
			new List<XYZ>();
			List<XYZ> list = new List<XYZ>();
			foreach (List<Curve> list2 in mergeRooms)
			{
				if (list2.Count != 4)
				{
					lstNotMergeArea.Add(list2);
				}
				else
				{
					List<XYZ> list3 = this.CalculateSprinklersPoints(list2);
					if (list3 == null)
					{
						lstNotMergeArea.Add(list2);
					}
					else if (list3.Count > 0)
					{
						list.AddRange(list3);
					}
				}
			}
			List<XYZ> list4 = new List<XYZ>();
			foreach (List<Curve> list5 in lstNotMergeArea)
			{
				if (list5.Count != 2)
				{
					List<Curve> ruleRectangle = this.NotRuleRoomChangeRule(list5);
					List<List<Curve>> allCloseCurves = this.GetAllCloseCurves(list5);
					List<XYZ> list6 = this.CalculateSprinklersPoints(ruleRectangle);
					if (list6 != null)
					{
						if (allCloseCurves.Count == 0)
						{
							list4.AddRange(list6);
						}
						else
						{
							foreach (XYZ xyz in list6)
							{
								if (allCloseCurves[0].Count > 0 && (GroundStorehouseNozzle.PointInPloygon(allCloseCurves[0], xyz) == 1 || GroundStorehouseNozzle.PointInPloygon(allCloseCurves[0], xyz) == 0))
								{
									bool flag = false;
									using (List<XYZ>.Enumerator enumerator3 = list4.GetEnumerator())
									{
										while (enumerator3.MoveNext())
										{
											if (enumerator3.Current.DistanceTo(xyz) < 1.0)
											{
												flag = true;
											}
										}
									}
									if (!flag)
									{
										list4.Add(xyz);
									}
								}
							}
						}
					}
				}
			}
			list.AddRange(list4);
			return list;
		}

		public static IList<Element> GetInSpaceColumn(IList<Element> eles, List<Curve> roomCurves)
		{
			IList<Element> list = new List<Element>();
			foreach (Element element in eles)
			{
				XYZ pt = new XYZ();
				XYZ xyz = new XYZ();
				XYZ xyz2 = new XYZ();
				LocationPoint locationPoint = element.Location as LocationPoint;
				if (locationPoint != null)
				{
					pt = locationPoint.Point;
					if (GroundStorehouseNozzle.PointInPloygon(roomCurves, pt) == 1)
					{
						list.Add(element);
					}
				}
				else
				{
					LocationCurve locationCurve = element.Location as LocationCurve;
					xyz = (locationCurve.Curve as Line).GetEndPoint(0);
					xyz2 = (locationCurve.Curve as Line).GetEndPoint(1);
					if (GroundStorehouseNozzle.PointInPloygon(roomCurves, new XYZ(xyz.X, xyz.Y, 0.0)) == 1 && GroundStorehouseNozzle.PointInPloygon(roomCurves, new XYZ(xyz2.X, xyz2.Y, 0.0)) == 1)
					{
						list.Add(element);
					}
				}
			}
			return list;
		}

		public List<XYZ> CalculateSprinklersPoints(List<Curve> ruleRectangle)
		{
			List<XYZ> list = new List<XYZ>();
			try
			{
				double num = 3400.0;
				double num2 = 2400.0;
				double num3 = 1700.0;
				double num4 = 500.0;
				int num5 = 50;
				bool flag = false;
				ruleRectangle = GroundStorehouseNozzle.SortListCurve(ruleRectangle, out flag);
				if (ruleRectangle.Count != 4)
				{
					ruleRectangle = GroundStorehouseNozzle.SortListCurves(ruleRectangle, out flag);
					if (ruleRectangle.Count != 4)
					{
						return null;
					}
				}
				Line line = ruleRectangle[0] as Line;
				Line line2 = ruleRectangle[1] as Line;
				Line line3 = ruleRectangle[2] as Line;
				Line line4 = ruleRectangle[3] as Line;
				XYZ endPoint = line.GetEndPoint(0);
				XYZ endPoint2 = line.GetEndPoint(1);
				XYZ endPoint3 = line2.GetEndPoint(0);
				XYZ endPoint4 = line2.GetEndPoint(1);
				XYZ endPoint5 = line3.GetEndPoint(0);
				XYZ endPoint6 = line3.GetEndPoint(1);
				XYZ endPoint7 = line4.GetEndPoint(0);
				XYZ endPoint8 = line4.GetEndPoint(1);
				List<XYZ> pointOfDividedLine = this.GetPointOfDividedLine((int)num, (int)num2, (int)num3, (int)num4, num5, endPoint, endPoint2);
				double num6 = pointOfDividedLine[0].DistanceTo(endPoint) * 304.8;
				double num7 = (50.0 - num6 % (double)num5) / 304.8;
				XYZ xyz = (endPoint2 - endPoint).Normalize();
				List<XYZ> list2 = new List<XYZ>();
				if (num6 % (double)num5 != 0.0)
				{
					using (List<XYZ>.Enumerator enumerator = pointOfDividedLine.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							XYZ xyz2 = enumerator.Current;
							XYZ item = xyz2 + xyz * num7;
							list2.Add(item);
						}
						goto IL_1A5;
					}
				}
				list2 = pointOfDividedLine;
				IL_1A5:
				List<Line> list3 = new List<Line>();
				List<Line> list4 = new List<Line>();
				foreach (XYZ xyz3 in list2)
				{
					YJKLine hyline = new YJKLine(endPoint5, endPoint6);
					hyline.MakeUnBound();
					XYZ project = hyline.GetProject(xyz3);
					list3.Add(Line.CreateBound(project, xyz3));
				}
				foreach (XYZ xyz4 in this.GetPointOfDividedLine((int)num, (int)num2, (int)num3, (int)num4, num5, endPoint3, endPoint4))
				{
					YJKLine hyline2 = new YJKLine(endPoint7, endPoint8);
					hyline2.MakeUnBound();
					XYZ project2 = hyline2.GetProject(xyz4);
					list4.Add(Line.CreateBound(project2, xyz4));
				}
				foreach (Line line5 in list3)
				{
					YJKLine hyLineX = new YJKLine(line5);
					using (List<Line>.Enumerator enumerator3 = list4.GetEnumerator())
					{
						while (enumerator3.MoveNext())
						{
							Line yLine = enumerator3.Current;
							new YJKLine(yLine);
							if (hyLineX.IntersectionPoint(yLine) != null && ((from s in list
							where s.IsAlmostEqualTo(hyLineX.IntersectionPoint(yLine), 0.0001)
							select s).Count<XYZ>() == 0 || (from s in list
							where s.IsAlmostEqualTo(hyLineX.IntersectionPoint(yLine), 0.0001)
							select s) == null))
							{
								list.Add(hyLineX.IntersectionPoint(yLine));
							}
						}
					}
				}
			}
			catch (Exception)
			{
				return list;
			}
			return list;
		}

		public List<Curve> NotRuleRoomChangeRule(List<Curve> notRuleRoom)
		{
			List<Curve> list = new List<Curve>();
			try
			{
				XYZ xyz = new XYZ();
				XYZ xyz2 = new XYZ();
				List<XYZ> list2 = new List<XYZ>();
				foreach (Curve curve in notRuleRoom)
				{
					Line line = curve as Line;
					XYZ endPoint = line.GetEndPoint(0);
					XYZ endPoint2 = line.GetEndPoint(1);
					list2.Add(endPoint);
					list2.Add(endPoint2);
				}
				GroundStorehouseNozzle.GetBoundaryPoint(list2, out xyz, out xyz2);
				XYZ xyz3 = new XYZ(xyz.X, xyz.Y, 0.0);
				XYZ xyz4 = new XYZ(xyz2.X, xyz.Y, 0.0);
				XYZ xyz5 = new XYZ(xyz2.X, xyz2.Y, 0.0);
				XYZ xyz6 = new XYZ(xyz.X, xyz2.Y, 0.0);
				Line item = Line.CreateBound(xyz3, xyz4);
				Line item2 = Line.CreateBound(xyz4, xyz5);
				Line item3 = Line.CreateBound(xyz5, xyz6);
				Line item4 = Line.CreateBound(xyz6, xyz3);
				list.Add(item);
				list.Add(item2);
				list.Add(item3);
				list.Add(item4);
			}
			catch (Exception)
			{
				return list;
			}
			return list;
		}

		public List<XYZ> GetPointOfDividedLine(int maxDis, int minDis, int maxSide, int minSide, int disDivisor, XYZ sLinePnt, XYZ eLinePnt)
		{
			List<XYZ> list = new List<XYZ>();
			YJKLine hyline = new YJKLine(sLinePnt, eLinePnt);
			if (hyline.Line == null)
			{
				return list;
			}
			double num = hyline.Line.Length * 304.8;
			int i = Convert.ToInt32((num - num % (double)maxDis) / (double)maxDis);
			int num2 = maxDis - maxDis % disDivisor;
			int num3 = minDis + (disDivisor - minDis % disDivisor);
			int num4 = 0;
			int num5 = 0;
			if (i == 0)
			{
				list.Add(sLinePnt.Add(eLinePnt) / 2.0);
				return list;
			}
			while (i > 0)
			{
				for (int j = num2; j >= num3; j -= disDivisor)
				{
					if (num - (double)(i * j) >= (double)(2 * maxSide))
					{
						i = 0;
						break;
					}
					num4 = i;
					num5 = j;
				}
				if (i == 1)
				{
					break;
				}
				i--;
			}
			XYZ xyz = eLinePnt.Subtract(sLinePnt).Normalize();
			double num6 = (num - (double)(num4 * num5)) / 2.0;
			num6 += (double)disDivisor - num6 % (double)disDivisor;
			for (int k = 0; k <= num4; k++)
			{
				XYZ item = sLinePnt + num6 / 304.8 * xyz + (double)(k * num5) / 304.8 * xyz;
				list.Add(item);
			}
			return list;
		}

		public List<Element> LaySprinkler(UIApplication uiApp, List<XYZ> listPoint, FamilySymbol familySymbol, FormlaySprinklerBasement formLay)
		{
			Document document = uiApp.ActiveUIDocument.Document;
			List<Element> list = new List<Element>();
			ConnectHelper connectHelper = new ConnectHelper();
			try
			{
				if (listPoint != null && listPoint.Count > 0)
				{
					ElementSet elementSet = connectHelper.LayFamilyInstance(listPoint, familySymbol, document.ActiveView.GenLevel, 0, document);
					document.Regenerate();
					ConnectHelper connectHelper2 = new ConnectHelper();
					if (elementSet == null || elementSet.IsEmpty)
					{
						return list;
					}
					foreach (object obj in elementSet)
					{
						XYZ origin = connectHelper2.GetYJKElementConnector(obj as Element).Origin;
						XYZ xyz = new XYZ(0.0, 0.0, 1.0);
						Line line = Line.CreateBound(origin, origin.Add(xyz * 1.0));
						ElementTransformUtils.RotateElement(document, (obj as Element).Id, line, 0.0);
						this.AddParameter(uiApp, obj as Element, formLay);
						document.Regenerate();
						list.Add(document.GetElement((obj as Element).Id));
					}
				}
			}
			catch (Exception ex)
			{
				string message = ex.Message;
			}
			return list;
		}

		private void AddParameter(UIApplication uiApp, Element elem, FormlaySprinklerBasement formLay)
		{
			new HYParametersSetting(uiApp);
			Document document = uiApp.ActiveUIDocument.Document;
			Parameter parameter = elem.GetParameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
			if (parameter != null)
			{
				parameter.Set(document.ActiveView.GenLevel.Id);
			}
			Parameter parameter2 = elem.GetParameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
			if (parameter2 != null)
			{
				parameter2.Set(UnitConvert.CovertToAPI(formLay.layParameter.Elevation * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)2));
			}
			document.Regenerate();
		}

		public static double GetSprinklerDishToBeamButtom(Autodesk.Revit.DB.Document doc, BeamCellStruct beamStruct, Element sprinkler)
		{
			XYZ point = (sprinkler.Location as LocationPoint).Point;
			BeamData closedBeamToSprinkler = GroundStorehouseNozzle.GetClosedBeamToSprinkler(beamStruct, point);
			Line.CreateBound(closedBeamToSprinkler.SPoint, closedBeamToSprinkler.EPoint);
			ElementId elementId = sprinkler.GetParameter(BuiltInParameter.ELEM_TYPE_PARAM).AsElementId();
			string name = doc.GetElement(elementId).Name;
			int num = name.IndexOf("x");
			string empty = string.Empty;
			string value = string.Empty;
			if (num > 0)
			{
				name.Substring(0, num);
				value = name.Substring(num + 1, name.Length - num - 1);
			}
			return Convert.ToDouble(value) - beamStruct.floorBottomLevel;
		}

		public static BeamData GetClosedBeamToSprinkler(BeamCellStruct beamStruct, XYZ sprinklerPt)
		{
			BeamData result = null;
			double num = 0.0;
			foreach (BeamData beamData in beamStruct.lstBeam)
			{
				double distance = new YJKLine(beamData.SPoint, beamData.EPoint).GetDistance(sprinklerPt);
				if (distance < num)
				{
					num = distance;
					result = beamData;
				}
			}
			return result;
		}

		public double GetSprinklerToBeamSide(BeamCellStruct beamStruct, Element sprinkler)
		{
			return 0.0;
		}

		public List<Line> CheckCollisionType(Autodesk.Revit.DB.Document doc, SprinklerInfo collisionSprinkler, IList<Element> collisionList)
		{
			int num = collisionList.Count<Element>();
			List<Line> list = new List<Line>();
			XYZ point = (collisionSprinkler.CollisionSprinkler.Location as LocationPoint).Point;
			if (num == 1)
			{
				int integerValue = collisionList[0].Category.Id.IntegerValue;
				if (integerValue == -2000100 || integerValue == -2001330)
				{
					List<Line> clomnCurveList = this.GetClomnCurveList(collisionSprinkler, doc, collisionList[0]);
					Line shortestPath = this.GetShortestPath(point, clomnCurveList);
					list.Add(shortestPath);
				}
				else if (integerValue == -2001320)
				{
					List<Line> beamLineList = this.GetBeamLineList(doc, collisionSprinkler, collisionList[0]);
					Line shortestPath2 = this.GetShortestPath(point, beamLineList);
					new YJKLine(shortestPath2);
					list.Add(shortestPath2);
				}
				else if (integerValue == -2000011)
				{
					List<Line> wallLineList = this.GetWallLineList(collisionSprinkler, doc, collisionList[0]);
					Line shortestPath3 = this.GetShortestPath(point, wallLineList);
					new YJKLine(shortestPath3);
					list.Add(shortestPath3);
				}
				return list;
			}
			if (num == 2)
			{
				List<Line> list2 = new List<Line>();
				List<Line> list3 = new List<Line>();
				List<Line> list4 = new List<Line>();
				foreach (Element element in collisionList)
				{
					int integerValue2 = element.Category.Id.IntegerValue;
					if (integerValue2 == -2000100 || integerValue2 == -2001330)
					{
						list2 = this.GetClomnCurveList(collisionSprinkler, doc, element);
					}
					else if (integerValue2 == -2001320)
					{
						list3 = this.GetBeamLineList(doc, collisionSprinkler, element);
					}
					else if (integerValue2 == -2000011)
					{
						list4 = this.GetWallLineList(collisionSprinkler, doc, element);
					}
				}
				if (list3.Count > 0)
				{
					YJKLine hyline = new YJKLine(list3[0]);
					if (list2.Count > 0)
					{
						List<Line> list5 = new List<Line>();
						foreach (Line line in list2)
						{
							if (hyline.IsParallel(line))
							{
								list5.Add(line);
							}
						}
						list.AddRange(list3);
						if (list5.Count == 2)
						{
							list.AddRange(list5);
						}
					}
					else if (list4.Count > 0)
					{
						List<Line> list6 = new List<Line>();
						foreach (Line line2 in list4)
						{
							if (hyline.IsParallel(line2))
							{
								list6.Add(line2);
							}
						}
						list.AddRange(list3);
						if (list6.Count == 2)
						{
							list.AddRange(list6);
						}
					}
					else
					{
						list.AddRange(list3);
					}
					return list;
				}
				if (list4.Count > 0)
				{
					YJKLine hyline2 = new YJKLine(list4[0]);
					if (list2.Count > 0)
					{
						List<Line> list7 = new List<Line>();
						foreach (Line line3 in list2)
						{
							if (hyline2.IsParallel(line3))
							{
								list7.Add(line3);
							}
						}
						list.AddRange(list4);
						if (list7.Count == 2)
						{
							list.AddRange(list7);
						}
					}
				}
			}
			else if (num == 3)
			{
				foreach (Element element2 in collisionList)
				{
				}
			}
			return list;
		}

		public Line GetLineDistanceSprinkler(Autodesk.Revit.DB.Document doc, SprinklerInfo sprinklerInfo, IList<Element> collisionList)
		{
			List<Line> list = this.CheckCollisionType(doc, sprinklerInfo, collisionList);
			if (list.Count == 0)
			{
				return null;
			}
			if (list.Count == 1)
			{
				return list[0];
			}
			List<Line> list2 = new List<Line>();
			List<Line> list3 = new List<Line>();
			YJKLine hyline = new YJKLine(list[0]);
			XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
			XYZ xyz = (hyline.GetProject(point) - point).Normalize();
            //-xyz;
			foreach (Line line in list)
			{
				if ((new YJKLine(line).GetProject(point) - point).Normalize().IsAlmostEqualTo(xyz))
				{
					list2.Add(line);
				}
				else
				{
					list3.Add(line);
				}
			}
			Line result = null;
			if (list2.Count == 1 && list3.Count == 1)
			{
				YJKLine hyline2 = new YJKLine(list2[0]);
				YJKLine hyline3 = new YJKLine(list3[0]);
				if (hyline2.GetDistance(point) < hyline3.GetDistance(point))
				{
					result = list2[0];
				}
				else
				{
					result = list3[0];
				}
			}
			else if (list2.Count == 2 && list3.Count == 2)
			{
				YJKLine hyline4 = new YJKLine(list2[0]);
				YJKLine hyline5 = new YJKLine(list2[1]);
				Line line2;
				if (hyline4.GetDistance(point) > hyline5.GetDistance(point))
				{
					line2 = list2[0];
				}
				else
				{
					line2 = list2[1];
				}
				YJKLine hyline6 = new YJKLine(list3[0]);
				YJKLine hyline7 = new YJKLine(list3[1]);
				Line line3;
				if (hyline6.GetDistance(point) > hyline7.GetDistance(point))
				{
					line3 = list3[0];
				}
				else
				{
					line3 = list3[1];
				}
				YJKLine hyline8 = new YJKLine(line2);
				YJKLine hyline9 = new YJKLine(line3);
				if (hyline8.GetDistance(point) < hyline9.GetDistance(point))
				{
					result = line2;
				}
				else
				{
					result = line3;
				}
			}
			return result;
		}

		public void MoveCollision(Autodesk.Revit.DB.Document doc, SprinklerInfo sprinklerInfo)
		{
			IList<Element> collectionBySprinkler = GroundStorehouseNozzle.GetCollectionBySprinkler(doc, sprinklerInfo.CollisionSprinkler);
			if (collectionBySprinkler.Count <= 0 || collectionBySprinkler == null)
			{
				return;
			}
			Line lineDistanceSprinkler = this.GetLineDistanceSprinkler(doc, sprinklerInfo, collectionBySprinkler);
			if (lineDistanceSprinkler == null)
			{
				return;
			}
			XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
			YJKLine hyline = new YJKLine(lineDistanceSprinkler);
			XYZ xyz = new XYZ();
			XYZ project = hyline.GetProject(point);
			XYZ xyz2 = (project - point).Normalize();
			double num = 0.16404199475065617;
			double num2 = (double)((int)(project.DistanceTo(point) / num) + 2) * num;
			XYZ xyz3 = point + xyz2 * num2;
			if (!this.JudgeDistanceIsSatisfy(sprinklerInfo, xyz3))
			{
				this.NotSatisfySprinklerId.Add(sprinklerInfo.CollisionSprinkler.Id);
			}
			xyz = xyz3 - point;
			ElementTransformUtils.MoveElement(doc, sprinklerInfo.CollisionSprinkler.Id, xyz);
			IList<Element> collectionBySprinkler2 = GroundStorehouseNozzle.GetCollectionBySprinkler(doc, sprinklerInfo.CollisionSprinkler);
			if (collectionBySprinkler2.Count <= 0 || collectionBySprinkler2 == null)
			{
				return;
			}
			this.MoveCollision(doc, sprinklerInfo);
		}

		public bool PillarAside(List<SprinklerInfo> sprinklers, UIApplication uiApp)
		{
			bool result = false;
			try
			{
				foreach (SprinklerInfo sprinklerInfo in sprinklers)
				{
					this.MoveCollisionColumnSprinkler(uiApp.ActiveUIDocument.Document, sprinklerInfo, 50);
				}
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			return result;
		}

		public void MoveCollisionColumnSprinkler(Autodesk.Revit.DB.Document doc, SprinklerInfo sprinklerInfo, int multiple)
		{
			List<Line> lines = null;
			XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
			List<Line> list = this.CalcutePointToLine(lines, point);
			YJKLine hyline = new YJKLine(list[0]);
			YJKLine hyline2 = new YJKLine(list[1]);
			XYZ xyz = new XYZ();
			XYZ xyz2 = new XYZ();
			XYZ project = hyline.GetProject(point);
			XYZ xyz3 = (project - point).Normalize();
			double num = (double)multiple / 304.8;
			double num2 = (double)((int)(project.DistanceTo(point) / num) + 2) * num;
			xyz2 = point + xyz3 * num2;
			if (!this.JudgeDistanceIsSatisfy(sprinklerInfo, xyz2))
			{
				XYZ project2 = hyline2.GetProject(point);
				XYZ xyz4 = (project2 - point).Normalize();
				double num3 = (double)((int)(project2.DistanceTo(point) / num) + 2) * num;
				xyz2 = point + xyz4 * num3;
				if (!this.JudgeDistanceIsSatisfy(sprinklerInfo, xyz2))
				{
					this.NotSatisfySprinklerId.Add(sprinklerInfo.CollisionSprinkler.Id);
				}
			}
			xyz = xyz2 - point;
			ElementTransformUtils.MoveElement(doc, sprinklerInfo.CollisionSprinkler.Id, xyz);
		}

		public bool JudgeDistanceIsSatisfy(SprinklerInfo sprinklerInfo, XYZ finalTempPoint)
		{
			bool result = false;
			foreach (Element element in sprinklerInfo.AroundSprinklers)
			{
				result = true;
				XYZ point = (element.Location as LocationPoint).Point;
				double num = finalTempPoint.DistanceTo(point);
                if (num < UnitConvert.CovertToAPI(2400.0, (DisplayUnitType)2) || num > UnitConvert.CovertToAPI(3400.0, (Autodesk.Revit.DB.DisplayUnitType)2))
				{
					result = false;
				}
			}
			return result;
		}

		public List<Line> GetClomnCurveList(SprinklerInfo sprinklerInfo, Autodesk.Revit.DB.Document doc, Element collisionEle)
		{
			List<Line> list = new List<Line>();
			try
			{
				XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
				BoundingBoxXYZ boundingBoxXYZ = collisionEle.get_BoundingBox(doc.ActiveView);
				double x = boundingBoxXYZ.Min.X;
				double x2 = boundingBoxXYZ.Max.X;
				double y = boundingBoxXYZ.Min.Y;
				double y2 = boundingBoxXYZ.Max.Y;
				XYZ xyz = new XYZ(x, y2, point.Z);
				XYZ xyz2 = new XYZ(x, y, point.Z);
				XYZ xyz3 = new XYZ(x2, y, point.Z);
				XYZ xyz4 = new XYZ(x2, y2, point.Z);
				Line item = Line.CreateBound(xyz, xyz2);
				Line item2 = Line.CreateBound(xyz2, xyz3);
				Line item3 = Line.CreateBound(xyz3, xyz4);
				Line item4 = Line.CreateBound(xyz4, xyz);
				list.Add(item);
				list.Add(item2);
				list.Add(item3);
				list.Add(item4);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			return list;
		}

		public List<Line> GetWallLineList(SprinklerInfo sprinklerInfo, Autodesk.Revit.DB.Document doc, Element collisionEle)
		{
			List<Line> list = new List<Line>();
			try
			{
				XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
				Wall wall = collisionEle as Wall;
				if (wall != null)
				{
					double num = wall.WallType.GetParameter("厚度").AsDouble() / 2.0;
					Curve curve = (wall.Location as LocationCurve).Curve;
					XYZ xyz = new XYZ(curve.GetEndPoint(0).X, curve.GetEndPoint(0).Y, point.Z);
					XYZ xyz2 = new XYZ(curve.GetEndPoint(1).X, curve.GetEndPoint(1).Y, point.Z);
					XYZ xyz3 = new XYZ(0.0, 0.0, 1.0);
					XYZ xyz4 = xyz2 - xyz;
					XYZ xyz5 = xyz3.Subtract(xyz4).Normalize();
					XYZ xyz6 = xyz + xyz5 * num;
					XYZ xyz7 = xyz2 + xyz5 * num;
					XYZ xyz8 = xyz - xyz5 * num;
					XYZ xyz9 = xyz2 - xyz5 * num;
					Line item = Line.CreateBound(xyz6, xyz7);
					Line item2 = Line.CreateBound(xyz8, xyz9);
					list.Add(item);
					list.Add(item2);
				}
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			return list;
		}

		public void SetRoomBoundingFalse(List<Element> list, Autodesk.Revit.DB.Document doc)
		{
			SubTransaction subTransaction = new SubTransaction(doc);
			subTransaction.Start();
			try
			{
				foreach (Element elem in list)
				{
					if (elem.GetParameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING) != null)
					{
						elem.GetParameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0);
					}
				}
				subTransaction.Commit();
			}
			catch (Exception)
			{
				subTransaction.RollBack();
			}
		}

		public List<Line> CalcutePointToLine(List<Line> lines, XYZ ptCur)
		{
			List<Line> list = new List<Line>();
			List<double> list2 = new List<double>();
			Dictionary<Line, double> dictionary = new Dictionary<Line, double>();
			foreach (Line line in lines)
			{
				XYZ project = new YJKLine(line).GetProject(ptCur);
				dictionary.Add(line, ptCur.DistanceTo(project));
				list2.Add(ptCur.DistanceTo(project));
			}
			list2 = (from x in list2
			orderby x
			select x).ToList<double>();
			double num = list2[2];
			double num2 = list2[3];
			foreach (KeyValuePair<Line, double> keyValuePair in dictionary)
			{
				if (keyValuePair.Value == num)
				{
					dictionary.Remove(keyValuePair.Key);
					break;
				}
			}
			foreach (KeyValuePair<Line, double> keyValuePair2 in dictionary)
			{
				if (keyValuePair2.Value == num2)
				{
					dictionary.Remove(keyValuePair2.Key);
					break;
				}
			}
			foreach (KeyValuePair<Line, double> keyValuePair3 in dictionary)
			{
				list.Add(keyValuePair3.Key);
			}
			return list;
		}

		public bool BeamAside(IList<SprinklerInfo> collisionSprinkler, UIApplication uiApp)
		{
			bool result = false;
			try
			{
				foreach (SprinklerInfo sprinklerInfo in collisionSprinkler)
				{
					this.MoveCollisionBeamSprinkler(uiApp.ActiveUIDocument.Document, sprinklerInfo, 50);
				}
				result = true;
			}
			catch (Exception ex)
			{
				ex.ToString();
				result = false;
			}
			return result;
		}

		private void MoveCollisionBeamSprinkler(Autodesk.Revit.DB.Document doc, SprinklerInfo sprinklerInfo, int multiple)
		{
			object obj = null;
			XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
			YJKLine hyline = new YJKLine(new XYZ(0,0,0), new XYZ(1,1,1));
            YJKLine hyline2 = new YJKLine(new XYZ(0, 0, 0), new XYZ(1, 1, 1));
			XYZ xyz = new XYZ();
			XYZ xyz2 = new XYZ();
			XYZ project = hyline.GetProject(point);
			XYZ xyz3 = (project - point).Normalize();
			double num = (double)multiple / 304.8;
			double num2 = (double)((int)(project.DistanceTo(point) / num) + 2) * num;
			xyz2 = point + xyz3 * num2;
			if (!this.JudgeDistanceIsSatisfy(sprinklerInfo, xyz2))
			{
				XYZ project2 = hyline2.GetProject(point);
				XYZ xyz4 = (project2 - point).Normalize();
				double num3 = (double)((int)(project2.DistanceTo(point) / num) + 2) * num;
				xyz2 = point + xyz4 * num3;
				if (!this.JudgeDistanceIsSatisfy(sprinklerInfo, xyz2))
				{
					this.NotSatisfySprinklerId.Add(sprinklerInfo.CollisionSprinkler.Id);
				}
			}
			xyz = xyz2 - point;
			ElementTransformUtils.MoveElement(doc, sprinklerInfo.CollisionSprinkler.Id, xyz);
		}

		public List<Line> GetBeamLineList(Autodesk.Revit.DB.Document doc, SprinklerInfo sprinklerInfo, Element collisionEle)
		{
			List<Line> list = new List<Line>();
			LocationCurve locationCurve = collisionEle.Location as LocationCurve;
			XYZ point = (sprinklerInfo.CollisionSprinkler.Location as LocationPoint).Point;
			Line line = locationCurve.Curve as Line;
			XYZ endPoint = line.GetEndPoint(0);
			XYZ endPoint2 = line.GetEndPoint(1);
			ElementId elementId = collisionEle.GetParameter(BuiltInParameter.ELEM_TYPE_PARAM).AsElementId();
			string name = doc.GetElement(elementId).Name;
			int num = name.IndexOf("x");
			string value = string.Empty;
			if (num > 0)
			{
				value = name.Substring(0, num);
			}
			double num2 = Convert.ToDouble(value) / 304.8;
			List<XYZ> list2 = new List<XYZ>();
			((ICollection<XYZ>)list2).Add(endPoint);
			((ICollection<XYZ>)list2).Add(endPoint2);
			IList<XYZ> list3 = new List<XYZ>();
			IList<XYZ> list4 = new List<XYZ>();
			list3 = GroundStorehouseNozzle.OffsetCurve(list2, num2, point.Z);
			list4 = GroundStorehouseNozzle.OffsetCurve(list2, -num2, point.Z);
			XYZ xyz = new XYZ(list3[0].X, list3[0].Y, point.Z);
			XYZ xyz2 = new XYZ(list3[1].X, list3[1].Y, point.Z);
			XYZ xyz3 = new XYZ(list4[0].X, list4[0].Y, point.Z);
			XYZ xyz4 = new XYZ(list4[1].X, list4[1].Y, point.Z);
			list.Add(Line.CreateBound(xyz, xyz2));
			list.Add(Line.CreateBound(xyz3, xyz4));
			return list;
		}

		public static IList<XYZ> OffsetCurve(IList<XYZ> srcPts, double dOffSet, double dZOffset)
		{
			IList<XYZ> list = new List<XYZ>();
			IList<XYZ> list2 = new List<XYZ>();
			for (int i = 0; i < srcPts.Count; i++)
			{
				if (i == 0)
				{
					list2.Add(srcPts[i]);
				}
				else if (srcPts[i].DistanceTo(list2.Last<XYZ>()) > 0.001)
				{
					list2.Add(srcPts[i]);
				}
			}
			if (list2.Count < 2)
			{
				return list;
			}
			XYZ xyz = new XYZ(0.0, 0.0, 1.0) * dZOffset;
			if (list2.Count == 2)
			{
				XYZ xyz2 = list2[1] - list2[0];
				xyz2 = new XYZ(-xyz2.Y, xyz2.X, 0.0);
				xyz2 = xyz2.Normalize();
				list.Add(list2[0] - dOffSet * xyz2 + xyz);
				list.Add(list2[1] - dOffSet * xyz2 + xyz);
				return list;
			}
			for (int j = 1; j < list2.Count - 1; j++)
			{
				XYZ xyz3 = list2[j - 1];
				XYZ xyz4 = list2[j];
				XYZ xyz5 = list2[j + 1];
				XYZ xyz6 = xyz4 - xyz3;
				xyz6 = new XYZ(xyz6.X, xyz6.Y, 0.0);
				xyz6 = xyz6.Normalize();
				XYZ xyz7 = new XYZ(-xyz6.Y, xyz6.X, 0.0);
				XYZ xyz8 = xyz5 - xyz4;
				xyz8 = new XYZ(xyz8.X, xyz8.Y, 0.0);
				xyz8 = xyz8.Normalize();
				XYZ xyz9 = new XYZ(-xyz8.Y, xyz8.X, 0.0);
				if (j == 1)
				{
					list.Add(xyz3 - dOffSet * xyz7 + xyz);
				}
				if (xyz7.IsAlmostEqualTo(xyz9))
				{
					list.Add(xyz4 - dOffSet * xyz7 + xyz);
				}
				else
				{
					XYZ xyz10 = xyz7 + xyz9;
					xyz10 = xyz10.Normalize();
					double d = xyz7.AngleTo(xyz10);
					list.Add(xyz4 - dOffSet * xyz10 / Math.Cos(d) + xyz);
				}
				if (j == list2.Count - 2)
				{
					list.Add(xyz5 - dOffSet * xyz9 + xyz);
				}
			}
			return list;
		}

		public void ParkingIdent(List<Element> sprinklers, UIApplication uiApp, double offset)
		{
			Document document = uiApp.ActiveUIDocument.Document;
			List<Element> list = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Parking).OfClass(typeof(FamilyInstance)).ToElements().ToList<Element>();
			List<Parking> list2 = new List<Parking>();
			RecSprinklerHelper recSprinklerHelper = new RecSprinklerHelper(document);
			double z = UnitConvert.CovertToAPI(offset * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)2);
			foreach (Element e in list)
			{
				Parking parking = new Parking(e, z, document, null);
				if (parking.center != null && parking.rr != null)
				{
					list2.Add(parking);
				}
			}
			list2.AddRange(recSprinklerHelper.GetLinkDocPakings(z));
			double[] viewRange = RevitAPIUIOperate.GetViewRange2(document.ActiveView, false);
			ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Sprinklers);
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
			List<Parking> list3 = new List<Parking>();
			foreach (Parking parking2 in list2)
			{
				BoundingBoxXYZ boundingBoxXYZ = parking2.ele.get_BoundingBox(document.ActiveView);
				LogicalAndFilter logicalAndFilter = new LogicalAndFilter(new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(viewRange, boundingBoxXYZ.Min, boundingBoxXYZ.Max)), elementCategoryFilter);
				if (filteredElementCollector.WherePasses(logicalAndFilter).ToElements().ToList<Element>().Count == 0)
				{
					list3.Add(parking2);
				}
			}
			double num = (double)3400 / 304.8;
			foreach (Parking parking3 in list3)
			{
				BoundingBoxXYZ boundingBoxXYZ2 = parking3.ele.get_BoundingBox(document.ActiveView);
				XYZ point = new XYZ(boundingBoxXYZ2.Min.X - num, boundingBoxXYZ2.Min.Y - num, boundingBoxXYZ2.Min.Z);
				XYZ point2 = new XYZ(boundingBoxXYZ2.Max.X + num, boundingBoxXYZ2.Max.Y + num, boundingBoxXYZ2.Max.Z);
				LogicalAndFilter logicalAndFilter2 = new LogicalAndFilter(new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(viewRange, point, point2)), elementCategoryFilter);
				List<Element> source = filteredElementCollector.WherePasses(logicalAndFilter2).ToElements().ToList<Element>();
				this.SetMoveSprinklers(document, parking3, source.ToList<Element>());
			}
		}

		public void SetMoveSprinklers(Autodesk.Revit.DB.Document doc, Parking park, List<Element> collection)
		{
			if (collection.Count<Element>() == 0)
			{
				return;
			}
			double num = 0.16404199475065617;
			List<Line> list = new List<Line>();
			list.Add(park.rr.l1);
			list.Add(park.rr.l2);
			list.Add(park.rr.l3);
			list.Add(park.rr.l4);
			Element element = collection[0];
			XYZ point = (element.Location as LocationPoint).Point;
			List<Dictionary<Element, double>> list2 = new List<Dictionary<Element, double>>();
			Dictionary<Element, double> minElement = this.GetMinElement(collection, park.rr.l1, point.Z);
			Dictionary<Element, double> minElement2 = this.GetMinElement(collection, park.rr.l2, point.Z);
			Dictionary<Element, double> minElement3 = this.GetMinElement(collection, park.rr.l3, point.Z);
			Dictionary<Element, double> minElement4 = this.GetMinElement(collection, park.rr.l4, point.Z);
			list2.Add(minElement);
			list2.Add(minElement2);
			list2.Add(minElement3);
			list2.Add(minElement4);
			int index = 0;
			element = this.GetMinElement(list2, out index);
			XYZ point2 = (element.Location as LocationPoint).Point;
			XYZ xyz = new YJKLine(list[index]).GetProject(point2);
			xyz = new XYZ(xyz.X, xyz.Y, point2.Z);
			XYZ xyz2 = (xyz - point2).Normalize();
			double num2 = (double)((int)(xyz.DistanceTo(point2) / num) + 2);
			XYZ xyz3 = point2 + xyz2 * (num2 * num) - point2;
			ElementTransformUtils.MoveElement(doc, element.Id, xyz3);
		}

		public Dictionary<Element, double> GetMinElement(IList<Element> collection, Line line, double offset)
		{
			XYZ endPoint = line.GetEndPoint(0);
			XYZ endPoint2 = line.GetEndPoint(1);
			YJKLine hyline = new YJKLine(Line.CreateBound(new XYZ(endPoint.X, endPoint.Y, offset), new XYZ(endPoint2.X, endPoint2.Y, offset)));
			Dictionary<Element, double> dictionary = new Dictionary<Element, double>();
			Element element = collection[0];
			XYZ point = (element.Location as LocationPoint).Point;
			double num = hyline.GetDistance(point);
			foreach (Element element2 in collection)
			{
				XYZ point2 = (element2.Location as LocationPoint).Point;
				double distance = hyline.GetDistance(point2);
				if (num > distance)
				{
					num = distance;
					element = element2;
				}
			}
			dictionary.Add(element, num);
			return dictionary;
		}

		public Element GetMinElement(List<Dictionary<Element, double>> lstDic, out int index)
		{
			Element key = lstDic[0].First<KeyValuePair<Element, double>>().Key;
			double num = lstDic[0].First<KeyValuePair<Element, double>>().Value;
			index = 0;
			int num2 = 0;
			foreach (Dictionary<Element, double> source in lstDic)
			{
				double value = source.First<KeyValuePair<Element, double>>().Value;
				if (num > value)
				{
					num = value;
					key = source.First<KeyValuePair<Element, double>>().Key;
					index = num2;
				}
				num2++;
			}
			return key;
		}

		public double[] GetArrayByLis(List<double> listPointsArray)
		{
			double[] array = new double[listPointsArray.Count];
			for (int i = 0; i < listPointsArray.Count; i++)
			{
				array[i] = listPointsArray[i];
			}
			return array;
		}

		public List<double> GetArrayByAllCurves(List<Curve> allRoomBoundary)
		{
			List<double> list = new List<double>();
			foreach (Curve curve in allRoomBoundary)
			{
				XYZ hyendPoint = curve.GetEndPoint(0);
				XYZ hyendPoint2 = curve.GetEndPoint(1);
				list.Add(hyendPoint.X);
				list.Add(hyendPoint.Y);
				list.Add(hyendPoint2.X);
				list.Add(hyendPoint2.Y);
			}
			return list;
		}

		public List<List<Curve>> GetAllCloseCurves(List<double> allPointValue, List<int> allCloseZones)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			int num = 0;
			int num2 = 0;
			List<Curve> list2 = new List<Curve>();
			int i = 0;
			while (i < allPointValue.Count)
			{
				if (i < allCloseZones[num] * 4 + num2)
				{
					XYZ start = new XYZ(allPointValue[i], allPointValue[i + 1], 0.0);
					XYZ end = new XYZ(allPointValue[i + 2], allPointValue[i + 3], 0.0);
					list2.Add(new YJKLine(start, end).Line);
					i += 4;
				}
				if (i == allCloseZones[num] * 4 + num2)
				{
					num2 += allCloseZones[num] * 4;
					num++;
					list.Add(list2);
					list2 = new List<Curve>();
				}
			}
			return list;
		}

		public static bool IsMatchedDisToBeam(double disToBeamBottom, double disToBeamCurve)
		{
			return disToBeamBottom < 0.0 || (disToBeamBottom == 0.0 && disToBeamCurve > 0.0) || (disToBeamBottom > 0.0 && disToBeamBottom <= 60.0 && disToBeamCurve >= 300.0) || (disToBeamBottom > 60.0 && disToBeamBottom <= 140.0 && disToBeamCurve >= 600.0) || (disToBeamBottom > 140.0 && disToBeamBottom <= 240.0 && disToBeamCurve >= 900.0) || (disToBeamBottom > 240.0 && disToBeamBottom <= 350.0 && disToBeamCurve >= 1200.0) || (disToBeamBottom > 350.0 && disToBeamBottom <= 450.0 && disToBeamCurve >= 1500.0) || (disToBeamBottom > 450.0 && disToBeamCurve >= 1800.0);
		}

		public static double DisToBeamBottom(FamilyInstance fInstance, double floorBottomLevel)
		{
			if (fInstance == null)
			{
				return -1.0;
			}
			double num = fInstance.GetParameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).AsDouble();
			return floorBottomLevel - num;
		}

		public static IList<Element> GetElementsByRoomArea(Autodesk.Revit.DB.Document doc, Element element, ElementFilter elementFilter)
		{
			if (element == null || elementFilter == null)
			{
				return null;
			}
			BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(doc.ActiveView);
			LogicalAndFilter logicalAndFilter = new LogicalAndFilter(new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(RevitAPIUIOperate.GetViewRange2(doc.ActiveView, false), boundingBoxXYZ.Min, boundingBoxXYZ.Max)), elementFilter);
			List<Element> list = new FilteredElementCollector(doc).WherePasses(logicalAndFilter).ToElements().ToList<Element>();
			IEnumerable<Document> linkDocuments = doc.GetLinkDocuments();
			if (linkDocuments == null)
			{
				return list;
			}
			foreach (Autodesk.Revit.DB.Document document in linkDocuments)
			{
				if (document != null)
				{
					IList<Element> elementsFormLinkedDoc = GroundStorehouseNozzle.GetElementsFormLinkedDoc(document, logicalAndFilter);
					list.AddRange(elementsFormLinkedDoc);
				}
			}
			return list;
		}

		private static IList<Element> GetElementsFormLinkedDoc(Autodesk.Revit.DB.Document doc, ElementFilter filter)
		{
			new List<Element>();
			return new FilteredElementCollector(doc).WherePasses(filter).ToElements();
		}

		public static IList<Element> GetColumnList(UIApplication uiApp, Element element)
		{
			IList<Element> list = new List<Element>();
			Document document = uiApp.ActiveUIDocument.Document;
			BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(document.ActiveView);
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBoxXYZ.Min - xyz, boundingBoxXYZ.Max + xyz), false);
			foreach (Element item in from elem in new FilteredElementCollector(document, uiApp.ActiveUIDocument.ActiveView.Id).OfClass(typeof(FamilyInstance)).WherePasses(boundingBoxIntersectsFilter).ToElements()
			let familyInstance = elem as FamilyInstance
			where familyInstance.Category.Id.IntegerValue == -2000100 || familyInstance.Category.Id.IntegerValue == -2001330
			select familyInstance)
			{
				list.Add(item);
			}
			return list;
		}

		public static IList<Element> GetBeamList(UIApplication uiApp, Element element)
		{
			IList<Element> list = new List<Element>();
			Document document = uiApp.ActiveUIDocument.Document;
			BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(document.ActiveView);
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBoxXYZ.Min - xyz, boundingBoxXYZ.Max + xyz), false);
			foreach (Element item in from elem in new FilteredElementCollector(document, uiApp.ActiveUIDocument.ActiveView.Id).OfClass(typeof(FamilyInstance)).WherePasses(boundingBoxIntersectsFilter).ToElements()
			let familyInstance = elem as FamilyInstance
			where familyInstance.Category.Id.IntegerValue == -2001320
			select familyInstance)
			{
				list.Add(item);
			}
			return list;
		}

		public static IList<Element> GetWallList(UIApplication uiApp, Element element)
		{
			IList<Element> list = new List<Element>();
			Document document = uiApp.ActiveUIDocument.Document;
			BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(document.ActiveView);
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBoxXYZ.Min - xyz, boundingBoxXYZ.Max + xyz), false);
			foreach (Element item in from elem in new FilteredElementCollector(document, uiApp.ActiveUIDocument.ActiveView.Id).OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements()
			let familyInstance = elem as FamilyInstance
			where familyInstance.Category.Id.IntegerValue == -2000011
			select familyInstance)
			{
				list.Add(item);
			}
			return list;
		}

		public static IList<Element> GetSprinklersIntersectBeam(Autodesk.Revit.DB.Document doc, FamilyInstance bream, IList<Element> sprinklers)
		{
			double breamThickness = GroundStorehouseNozzle.GetBreamThickness(bream);
			IList<CurveLoop> list = new List<CurveLoop>();
			CurveLoop breamOutLine = GroundStorehouseNozzle.GetBreamOutLine(bream);
			list.Add(breamOutLine);
			Solid tagSolid = null;
			try
			{
				tagSolid = GeometryCreationUtilities.CreateExtrusionGeometry(list, -XYZ.BasisZ, breamThickness);
			}
			catch
			{
				return null;
			}
			return GroundStorehouseNozzle.GetElementByCollision(doc, tagSolid, (Autodesk.Revit.DB.BuiltInCategory)(-2008099));
		}

		public static IList<Element> GetSprinklersIntersectColumn(Autodesk.Revit.DB.Document doc, FamilyInstance column, IList<Element> sprinklers)
		{
			IEnumerator<GeometryObject> enumerator = column.get_Geometry(new Options
			{
                DetailLevel = (ViewDetailLevel)3
			}).GetEnumerator();
			enumerator.Reset();
			Solid solid = null;
			while (enumerator.MoveNext())
			{
				GeometryObject geometryObject = enumerator.Current;
				if (geometryObject is GeometryInstance)
				{
					IEnumerator<GeometryObject> enumerator2 = (geometryObject as GeometryInstance).GetInstanceGeometry().GetEnumerator();
					enumerator2.Reset();
					while (enumerator2.MoveNext())
					{
						GeometryObject geometryObject2 = enumerator2.Current;
						if (geometryObject2 != null && geometryObject2 is Solid)
						{
							solid = (geometryObject2 as Solid);
						}
					}
				}
			}
			if (null != solid)
			{
				return GroundStorehouseNozzle.GetElementByCollision(doc, solid, (Autodesk.Revit.DB.BuiltInCategory)(-2008099));
			}
			return null;
		}

		public static List<Element> GetElementByCollision(Autodesk.Revit.DB.Document doc, Solid tagSolid, BuiltInCategory needElement)
		{
			List<Element> list = new List<Element>();
			if (tagSolid == null)
			{
				return list;
			}
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(tagSolid, false);
			filteredElementCollector.WherePasses(elementIntersectsSolidFilter);
			foreach (Element element in filteredElementCollector)
			{
                if (element.Category.Id.IntegerValue == (int)needElement)
				{
					list.Add(element);
				}
			}
			return list;
		}

		public static List<SprinklerInfo> GetElementByCollision(Autodesk.Revit.DB.Document doc, IList<Element> sprinklers, Element tagElement)
		{
			if (sprinklers == null || sprinklers.Count <= 0)
			{
				return null;
			}
			List<SprinklerInfo> list = new List<SprinklerInfo>();
			ICollection<ElementId> collection = (from x in sprinklers
			select x.Id).ToList<ElementId>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, collection);
			ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(tagElement);
			foreach (Element element in filteredElementCollector.WherePasses(elementIntersectsElementFilter).ToElements())
			{
				list.Add(new SprinklerInfo
				{
					CollisionSprinkler = element,
					AroundSprinklers = GroundStorehouseNozzle.GetNearSprinklers(doc, element)
				});
			}
			return list;
		}

		public static Element[] GetNearSprinklers(Autodesk.Revit.DB.Document doc, Element sprinkler)
		{
			double num = (double)3400 / 304.8;
			XYZ point = (sprinkler.Location as LocationPoint).Point;
			XYZ point2 = new XYZ(point.X - num, point.Y + num, point.Z);
			XYZ point3 = new XYZ(point.X + num, point.Y - num, point.Z);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(RevitAPIUIOperate.GetViewRange2(doc.ActiveView, false), point2, point3), 0.001);
			Element[] array = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sprinklers).WherePasses(boundingBoxIntersectsFilter).ToArray<Element>();
			XYZ xyz = XYZ.Zero;
			XYZ xyz2 = XYZ.Zero;
			for (int i = 0; i < array.Length - 1; i++)
			{
				for (int j = 0; j < array.Length - 1 - i; j++)
				{
					xyz = ((array[j] as FamilyInstance).Location as LocationPoint).Point;
					xyz2 = ((array[j + 1] as FamilyInstance).Location as LocationPoint).Point;
					if (point.DistanceTo(xyz) > point.DistanceTo(xyz2))
					{
						Element element = array[j];
						array[j] = array[j + 1];
						array[j + 1] = element;
					}
				}
			}
			return array.Take(4).ToArray<Element>();
		}

		public static bool GetNearWall(Autodesk.Revit.DB.Document doc, Element sprinkler)
		{
			double num = (double)1700 / 304.8;
			XYZ point = (sprinkler.Location as LocationPoint).Point;
			XYZ point2 = new XYZ(point.X - num, point.Y + num, point.Z);
			XYZ point3 = new XYZ(point.X + num, point.Y - num, point.Z);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(RevitAPIUIOperate.GetViewRange2(doc.ActiveView, false), point2, point3), 0.001);
			return new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WherePasses(boundingBoxIntersectsFilter).ToArray<Element>().Count<Element>() != 0;
		}

		public static bool IsIntersects(Autodesk.Revit.DB.Document doc, FamilyInstance sprinkler, Outline outline)
		{
			BoundingBoxXYZ boundingBoxXYZ = sprinkler.get_BoundingBox(doc.ActiveView);
			return new Outline(boundingBoxXYZ.Min, boundingBoxXYZ.Max).Intersects(outline, 0.001);
		}

		public static IList<Element> GetCollectionBySprinkler(Autodesk.Revit.DB.Document doc, Element sprinkler)
		{
			IList<Element> list = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(sprinkler);
			filteredElementCollector.WherePasses(elementIntersectsElementFilter).ToElements();
			foreach (Element element in filteredElementCollector)
			{
				if (element.Category.Id.IntegerValue == -2000011 || element.Category.Id.IntegerValue == -2001320 || element.Category.Id.IntegerValue == -2001330 || element.Category.Id.IntegerValue == -2000100)
				{
					list.Add(element);
				}
			}
			IEnumerable<Document> linkDocuments = doc.GetLinkDocuments();
			if (linkDocuments == null)
			{
				return list;
			}
			foreach (Autodesk.Revit.DB.Document document in linkDocuments)
			{
				if (document != null)
				{
					FilteredElementCollector filteredElementCollector2 = new FilteredElementCollector(document);
					ElementIntersectsElementFilter elementIntersectsElementFilter2 = new ElementIntersectsElementFilter(sprinkler);
					foreach (Element element2 in filteredElementCollector2.WherePasses(elementIntersectsElementFilter2).ToElements())
					{
						if (element2.Category.Id.IntegerValue == -2000011 || element2.Category.Id.IntegerValue == -2001320 || element2.Category.Id.IntegerValue == -2001330 || element2.Category.Id.IntegerValue == -2000100)
						{
							list.Add(element2);
						}
					}
				}
			}
			return list;
		}

		private static CurveLoop GetBreamOutLine(FamilyInstance bream)
		{
			Curve curve = (bream.Location as LocationCurve).Curve;
			CurveLoop curveLoop = new CurveLoop();
			XYZ xyz = GroundStorehouseNozzle.GetVerticalSide(bream) / 2.0;
			XYZ xyz2 = -xyz;
			XYZ xyz3 = curve.GetEndPoint(0) + xyz;
			XYZ xyz4 = curve.GetEndPoint(1) + xyz;
			XYZ xyz5 = curve.GetEndPoint(1) + xyz2;
			XYZ xyz6 = curve.GetEndPoint(0) + xyz2;
			double num = 0.0;
			Parameter parameter = bream.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE);
			if (parameter != null)
			{
				num = parameter.AsDouble();
			}
			xyz3 = new XYZ(xyz3.X, xyz3.Y, xyz3.Z + num);
			xyz4 = new XYZ(xyz4.X, xyz4.Y, xyz4.Z + num);
			xyz5 = new XYZ(xyz5.X, xyz5.Y, xyz5.Z + num);
			xyz6 = new XYZ(xyz6.X, xyz6.Y, xyz6.Z + num);
			Line line = Line.CreateBound(xyz3, xyz4);
			Line line2 = Line.CreateBound(xyz4, xyz5);
			Line line3 = Line.CreateBound(xyz5, xyz6);
			Line line4 = Line.CreateBound(xyz6, xyz3);
			curveLoop.Append(line);
			curveLoop.Append(line2);
			curveLoop.Append(line3);
			curveLoop.Append(line4);
			return curveLoop;
		}

		private static XYZ GetVerticalSide(FamilyInstance bream)
		{
			Curve curve = (bream.Location as LocationCurve).Curve;
			Transform transform = bream.GetTransform();
			Options options = new Options();
			options.ComputeReferences = true;
			options.DetailLevel = (ViewDetailLevel)2;
			GeometryElement geometryElement = bream.Symbol.get_Geometry(options);
			Solid solid = null;
			foreach (GeometryObject geometryObject in geometryElement)
			{
				Solid solid2 = geometryObject as Solid;
				if (solid2 != null || solid2.Edges.Size != 0)
				{
					solid = solid2;
					break;
				}
			}
			if (solid == null)
			{
				return XYZ.Zero;
			}
			XYZ xyz = curve.GetEndPoint(1) - curve.GetEndPoint(0);
			try
			{
				xyz = new XYZ(xyz.X / xyz.GetLength(), xyz.Y / xyz.GetLength(), xyz.Z / xyz.GetLength());
			}
			catch
			{
			}
			XYZ result = null;
			double num = 0.0;
			foreach (object obj in solid.Edges)
			{
				Edge edge = (Edge)obj;
				double approximateLength = edge.ApproximateLength;
				Curve curve2 = edge.AsCurve();
				XYZ xyz2 = transform.OfPoint(curve2.GetEndPoint(1)) - transform.OfPoint(curve2.GetEndPoint(0));
				xyz2 = new XYZ(xyz2.X / xyz2.GetLength(), xyz2.Y / xyz2.GetLength(), xyz2.Z / xyz2.GetLength());
				if (!xyz2.IsAlmostEqualTo(XYZ.BasisZ) && !xyz2.IsAlmostEqualTo(-XYZ.BasisZ) && Math.Abs(xyz2.DotProduct(xyz)) <= 0.005 && approximateLength >= num)
				{
					num = approximateLength;
					result = xyz2;
				}
			}
			return result;
		}

		private static double GetBreamThickness(FamilyInstance bream)
		{
			Options options = new Options();
			options.ComputeReferences = true;
			options.DetailLevel = (ViewDetailLevel)2;
			GeometryElement geometryElement = bream.Symbol.get_Geometry(options);
			Solid solid = null;
			foreach (GeometryObject geometryObject in geometryElement)
			{
				Solid solid2 = geometryObject as Solid;
				if (solid2 != null || solid2.Edges.Size != 0)
				{
					solid = solid2;
					break;
				}
			}
			if (solid == null)
			{
				return -1.0;
			}
			Curve curve = (bream.Location as LocationCurve).Curve;
			Line template = (from r in GroundStorehouseNozzle.GetLineToSolid(solid, curve, XYZ.BasisZ, Math.PI*.5)
			orderby r.Length descending
			select r).ToList<Line>()[0];
			XYZ normal = curve.GetEndPoint(1) - curve.GetEndPoint(0);
			return GroundStorehouseNozzle.GetLineToSolid(solid, template, normal, Math.PI*.5).Max((Line r) => r.Length);
		}

		public static List<Line> GetLineToSolid(Solid solid, Curve template, XYZ normal, double dAngle)
		{
			List<Line> list = new List<Line>();
			double num = Math.Cos(dAngle);
			XYZ xyz = template.GetEndPoint(1) - template.GetEndPoint(0);
			xyz = xyz.Normalize();
			foreach (object obj in solid.Edges)
			{
				Edge edge = (Edge)obj;
				if (Math.Abs(Math.Abs((edge.AsCurve().GetEndPoint(1) - edge.AsCurve().GetEndPoint(0)).Normalize().DotProduct(xyz)) - num) < 0.05 && edge.AsCurve() as Line != null)
				{
					list.Add(edge.AsCurve() as Line);
				}
			}
			list = (from k in list
			where Math.Abs((k.GetEndPoint(1) - k.GetEndPoint(0)).Normalize().DotProduct(normal.Normalize())) < 0.05
			select k).ToList<Line>();
			return list;
		}

		public Line GetShortestPath(XYZ point, IList<Line> lineList)
		{
			if (lineList == null || lineList.Count <= 0)
			{
				return null;
			}
			Line result = null;
			double value = 0.0;
			for (int i = 0; i < lineList.Count; i++)
			{
				lineList[i].MakeUnbound();
				XYZ project = new YJKLine(lineList[i]).GetProject(point);
				double num = point.DistanceTo(project);
				if (i == 0)
				{
					value = num;
					result = lineList[i];
				}
				else if (Math.Round(num, 2) < Math.Round(value, 2))
				{
					value = num;
					result = lineList[i];
				}
			}
			return result;
		}

		public List<List<Element>> SprinklerAddParameter(List<Element> listElement, Autodesk.Revit.DB.Document doc, List<Element> lstRoomRegion, LayBasementSprinklerParameter param)
		{
			BoundingBoxXYZ boundingBoxXYZ = lstRoomRegion.First<Element>().get_BoundingBox(doc.ActiveView);
			XYZ xyz = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Min.Y, 0.0);
			XYZ xyz2 = new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Max.Y, 0.0);
			XYZ xyz3 = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Max.Y, 0.0);
			new AuxiliaryLineOperate();
			List<List<Element>> result = new List<List<Element>>();
			try
			{
				PipingSystemType pipingSystemType = null;
				double pipeDistance = 0.0;
				int num = 1;
				int index = 0;
				pipeDistance = param.Distance;
				num = param.LinkType;
				index = param.PiptType;
				foreach (Element element in YJKElementFilter.GetElementByClass(typeof(PipingSystemType), doc))
				{
					pipingSystemType = (element as PipingSystemType);
					if ((int)pipingSystemType.SystemClassification == 23)
					{
						break;
					}
				}
				PipeType pipeType = YJKElementFilter.GetElementByClass(typeof(PipeType), doc)[index] as PipeType;
				if (num == 3)
				{
					YJKLine hyline = new YJKLine(xyz, xyz3);
					hyline.MakeUnBound();
					Pipe pipe = Pipe.Create(doc, pipingSystemType.Id, pipeType.Id, doc.ActiveView.GenLevel.Id, xyz2, hyline.GetProject(xyz2));
					this.AddFirstRuleFitting(pipeType, doc);
					result = this.SprinklerConn(doc, listElement, pipeDistance, pipe);
				}
				if (num == 2)
				{
					Pipe pipe2 = Pipe.Create(doc, pipingSystemType.Id, pipeType.Id, doc.ActiveView.GenLevel.Id, xyz, xyz3);
					this.AddFirstRuleFitting(pipeType, doc);
					result = this.SprinklerConn(doc, listElement, pipeDistance, pipe2);
				}
			}
			catch (Exception ex)
			{
				string message = ex.Message;
			}
			return result;
		}

		private void AddFirstRuleFitting(PipeType pipeType, Autodesk.Revit.DB.Document doc)
		{
			string text = "";
			IList<ElementId> list = new List<ElementId>();
			list = UnifiedModified.GetSegmentFitting(pipeType, 1);
			if (list == null || list.Count < 1)
			{
				FamilySymbol familySymbolByName = YJKRevitTools.GetFamilySymbolByName("Fitting", "弯头_焊接", doc, ref text);
				UnifiedModified.SetSegmentFitting(pipeType, 1, familySymbolByName.Id, "弯头_焊接");
			}
			list = UnifiedModified.GetSegmentFitting(pipeType, 2);
			if (list == null || list.Count < 1)
			{
				FamilySymbol familySymbolByName2 = YJKRevitTools.GetFamilySymbolByName("Fitting", "变径三通_焊接", doc, ref text);
				UnifiedModified.SetSegmentFitting(pipeType, 2, familySymbolByName2.Id, "变径三通_焊接");
			}
		}

		public List<List<Element>> SprinklerConn(Autodesk.Revit.DB.Document doc, List<Element> listSprinklers, double pipeDistance, Pipe pipe)
		{
			if (listSprinklers.Count < 1)
			{
				return null;
			}
			List<List<Element>> list = new List<List<Element>>();
			Connector elementConnector = YJKRevitTools.GetElementConnector(listSprinklers[0]);
			bool flag = false;
			IList<Element> list2 = new List<Element>();
			Dictionary<Element, Element> dictionary = new Dictionary<Element, Element>();
			if (elementConnector.IsConnected)
			{
				flag = true;
				foreach (Element element in listSprinklers)
				{
					Element owner = YJKRevitTools.GetConnectConnector(YJKRevitTools.GetElementConnector(element)).Owner;
					list2.Add(owner);
					dictionary.Add(owner, element);
				}
			}
			double num = elementConnector.Radius * 2.0;
			pipe.GetParameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(num);
			doc.Regenerate();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			IList<AutoConnectParameter> list3 = null;
			IList<AutoConnectParameter> list4 = null;
			XYZ origin = hypiping.StartConnector.Connector.Origin;
			XYZ origin2 = hypiping.EndConnector.Connector.Origin;
			ConnectHelper connectHelper = new ConnectHelper();
			if (!flag)
			{
				list3 = connectHelper.InitYJKElement(pipe, listSprinklers);
			}
			else
			{
				list3 = connectHelper.InitHYPipe(pipe, list2);
			}
			list4 = connectHelper.PositionAssign(connectHelper.OrderByDistanceOfEnd(origin, origin2, list3), origin, origin2);
			XYZ basisZ = elementConnector.CoordinateSystem.BasisZ;
			IList<AutoConnectParameter> list5 = new List<AutoConnectParameter>();
			int num2 = 1;
			int i = 0;
			int count = list4.Count;
			string text = "";
			FamilySymbol familySymbolByName = YJKRevitTools.GetFamilySymbolByName("Fitting", "水管三通", doc, ref text);
			for (i = 0; i < count; i++)
			{
				int j;
				for (j = i; j < count; j++)
				{
					if (list4[j].IndexOfDuct != num2)
					{
						i = j - 1;
						break;
					}
					list5.Add(list4[j]);
				}
				if (i != j - 1)
				{
					i = j - 1;
				}
				if (list5.Count > 1)
				{
					if (!connectHelper.IsElementAlign(list5))
					{
						List<Element> list6 = new List<Element>();
						foreach (AutoConnectParameter autoConnectParameter in list5)
						{
							list6.Add(doc.GetElementById(autoConnectParameter.ElementId));
						}
					}
					this.PipeCollisionGroup(doc, list5, flag, pipeDistance, basisZ, pipe, num, list, list3, familySymbolByName, true);
				}
				list5.Clear();
				num2++;
			}
			if (flag)
			{
				List<List<Element>> list7 = new List<List<Element>>();
				foreach (List<Element> list8 in list)
				{
					List<Element> list9 = new List<Element>();
					foreach (Element key in list8)
					{
						Element element2 = null;
						if (dictionary.TryGetValue(key, out element2) && element2 != null)
						{
							list9.Add(element2);
						}
					}
					list7.Add(list9);
				}
				list = list7;
			}
			doc.DeleteElement(pipe);
			doc.Regenerate();
			return list;
		}

		private void PipeCollisionGroup(Autodesk.Revit.DB.Document doc, IList<AutoConnectParameter> branchParam, bool isUpDownSprinkler, double pipeDistance, XYZ sprinklerVector, Pipe pipe, double sprinklerDiameter, List<List<Element>> sprinkers, IList<AutoConnectParameter> acParam, FamilySymbol fs, bool flag = true)
		{
			IList<Element> list = new List<Element>();
			double num = 0.0;
			XYZ xyz = null;
			XYZ xyz2 = null;
			for (int i = 0; i < branchParam.Count - 1; i++)
			{
				for (int j = i + 1; j < branchParam.Count; j++)
				{
					if (!isUpDownSprinkler)
					{
						double num2 = YJKRevitTools.DistanceTwoXYZ(branchParam[i].LocationPoint.Point, branchParam[j].LocationPoint.Point);
						if (num2 > num)
						{
							num = num2;
							xyz = branchParam[i].LocationPoint.Point + pipeDistance * 1000.0 / 304.8 * sprinklerVector;
							xyz2 = branchParam[j].LocationPoint.Point + pipeDistance * 1000.0 / 304.8 * sprinklerVector;
						}
					}
					else
					{
						double num2 = YJKRevitTools.DistanceTwoXYZ(branchParam[i].PipePoint, branchParam[j].PipePoint);
						if (num2 > num)
						{
							num = num2;
							xyz = branchParam[i].PipePoint;
							xyz2 = branchParam[j].PipePoint;
						}
					}
				}
			}
			if (xyz != null)
			{
				Pipe pipe2 = YJKRevitTools.NewPipe(pipe, xyz, xyz2);
				List<Element> elementByCollision = this.GetElementByCollision(pipe2, doc);
				if (elementByCollision == null || elementByCollision.Count == 0 || !flag)
				{
					YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe2);
					hypiping.SetDiameter(sprinklerDiameter * 304.8);
					XYZ origin = hypiping.StartConnector.Origin;
					XYZ origin2 = hypiping.EndConnector.Origin;
					doc.Regenerate();
					foreach (AutoConnectParameter autoConnectParameter in branchParam)
					{
						list.Add(doc.GetElementById(autoConnectParameter.ElementId));
					}
					sprinkers.Add(list.ToList<Element>());
					branchParam.Clear();
					if (!isUpDownSprinkler)
					{
						this.PipeConnectHSprinklersByRectangle(pipe2, list, 1);
						return;
					}
					ConnectHelper connectHelper = new ConnectHelper();
					acParam = connectHelper.InitHYPipe(pipe2, list);
					list.Clear();
					IList<AutoConnectParameter> list2 = connectHelper.PositionAssign(connectHelper.OrderByDistanceOfEnd(origin, origin2, acParam), origin, origin2);
					HYPipeConnect hypipeConnect = new HYPipeConnect();
					for (int k = 0; k < list2.Count; k++)
					{
						string text = "temp";
						Pipe riserPipe = doc.GetElementById(list2[k].ElementId) as Pipe;
						pipe2 = hypipeConnect.GetNextPipe(origin, riserPipe, pipe2, doc, fs, ref text);
					}
					return;
				}
				else
				{
					doc.DeleteElement(pipe2);
					doc.Regenerate();
					YJKLine hyline = new YJKLine(xyz, xyz2);
					List<XYZ> divisionPointList = this.GetDivisionPointList(hyline, elementByCollision, xyz, xyz2);
					foreach (List<AutoConnectParameter> branchParam2 in this.GetNewGroup(branchParam, hyline, divisionPointList))
					{
						this.PipeCollisionGroup(doc, branchParam2, isUpDownSprinkler, pipeDistance, sprinklerVector, pipe, sprinklerDiameter, sprinkers, acParam, fs, false);
					}
				}
			}
		}

		private List<List<AutoConnectParameter>> GetNewGroup(IList<AutoConnectParameter> branchParam, YJKLine hyline, List<XYZ> divisionList)
		{
			List<List<AutoConnectParameter>> list = new List<List<AutoConnectParameter>>();
			XYZ xyz = (hyline.StartPoint - hyline.EndPoint).Normalize();
			foreach (XYZ xyz2 in divisionList)
			{
				List<AutoConnectParameter> list2 = new List<AutoConnectParameter>();
				foreach (AutoConnectParameter autoConnectParameter in branchParam)
				{
					XYZ xyz3 = (hyline.GetProject(autoConnectParameter.LocationPoint.Point) - xyz2).Normalize();
					if (xyz.IsAlmostEqualTo(xyz3, 0.001))
					{
						list2.Add(autoConnectParameter);
					}
				}
				if (list2.Count != 0)
				{
					foreach (AutoConnectParameter item in list2)
					{
						branchParam.Remove(item);
					}
					list.Add(list2);
				}
			}
			list.Add(branchParam.ToList<AutoConnectParameter>());
			return list;
		}

		private List<XYZ> GetDivisionPointList(YJKLine hyline, List<Element> list, XYZ bstartPoint, XYZ bendPoint)
		{
			List<XYZ> list2 = new List<XYZ>();
			foreach (Element element in list)
			{
				LocationCurve locationCurve = element.Location as LocationCurve;
				if (locationCurve == null)
				{
					LocationPoint locationPoint = element.Location as LocationPoint;
					if (locationPoint != null)
					{
						XYZ project = hyline.GetProject(locationPoint.Point);
						list2.Add(project);
					}
				}
				else
				{
					XYZ start = new XYZ(bstartPoint.X, bstartPoint.Y, 0.0);
					XYZ end = new XYZ(bendPoint.X, bendPoint.Y, 0.0);
					YJKLine hyline2 = new YJKLine(start, end);
					XYZ endPoint = locationCurve.Curve.GetEndPoint(0);
					XYZ endPoint2 = locationCurve.Curve.GetEndPoint(1);
					XYZ xyz = new XYZ(endPoint.X, endPoint.Y, 0.0);
					XYZ xyz2 = new XYZ(endPoint2.X, endPoint2.Y, 0.0);
					Line otherLine = Line.CreateBound(xyz, xyz2);
					XYZ xyz3 = hyline2.IntersectionPoint(otherLine);
					if (xyz3 != null)
					{
						XYZ project2 = hyline.GetProject(xyz3);
						list2.Add(project2);
					}
				}
			}
			return (from c in list2
			orderby c.DistanceTo(hyline.StartPoint)
			select c).ToList<XYZ>();
		}

		public List<Element> GetElementByCollision(Element tagElement, Autodesk.Revit.DB.Document doc)
		{
			List<Element> list = new List<Element>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementIntersectsElementFilter elementIntersectsElementFilter = new ElementIntersectsElementFilter(tagElement);
			filteredElementCollector.WherePasses(elementIntersectsElementFilter);
			foreach (Element element in filteredElementCollector)
			{
				if (element.Category.Id.IntegerValue == -2000011 || element.Category.Id.IntegerValue == -2000100 || element.Category.Id.IntegerValue == -2001320 || element.Category.Id.IntegerValue == -2001330)
				{
					list.Add(element);
				}
			}
			return list;
		}

		public bool PipeConnectHSprinklersByRectangle(Pipe pipe, IList<Element> listSprinklers, int connectType)
		{
			if (pipe == null || listSprinklers == null)
			{
				return true;
			}
			bool flag = false;
			IList<AutoConnectParameter> list = null;
			bool result;
			try
			{
				Document document = pipe.Document;
				pipe = new HYPipeConnect().CheckPipeLength(pipe, listSprinklers);
				ConnectHelper connectHelper = new ConnectHelper();
				IList<AutoConnectParameter> listParam = connectHelper.InitYJKElement(pipe, listSprinklers);
				new List<Connector>();
				IList<Connector> pipeConnectorEnd = connectHelper.GetPipeConnectorEnd(pipe);
				XYZ xyz = pipeConnectorEnd[0].Origin;
				XYZ origin = pipeConnectorEnd[1].Origin;
				list = connectHelper.PositionAssign(connectHelper.OrderByDistanceOfEnd(xyz, origin, listParam), xyz, origin);
				IList<AutoConnectParameter> list2 = new List<AutoConnectParameter>();
				int num = 1;
				int i = 0;
				for (i = 0; i < list.Count; i++)
				{
					int j;
					for (j = i; j < list.Count; j++)
					{
						if (list[j].IndexOfDuct != num)
						{
							i = j - 1;
							break;
						}
						list2.Add(list[j]);
					}
					if (i != j - 1)
					{
						i = j - 1;
					}
					if (list2.Count > 0)
					{
						if (list2.Count > 1)
						{
							if (!connectHelper.IsElementAlign(list2))
							{
								List<Element> list3 = new List<Element>();
								foreach (AutoConnectParameter autoConnectParameter in list2)
								{
									list3.Add(document.GetElementById(autoConnectParameter.ElementId));
								}
								connectHelper.AlignElement(xyz, origin, list3);
							}
						}
						else if (list2[0].PositionFlag == 3 && list2[0].VectorToDuct.GetLength() < 0.33)
						{
							connectHelper.AlignElement(xyz, origin, document.GetElementById(list2[0].ElementId));
							list2[0].PositionFlag = 1;
						}
						else if (list2[0].PositionFlag == 1 && list2[0].VectorToDuct.GetLength() > 0.0001)
						{
							connectHelper.AlignElement(xyz, origin, document.GetElementById(list2[0].ElementId));
						}
						else if (list2[0].PositionFlag == 2)
						{
							connectHelper.AlignElement(xyz, origin, document.GetElementById(list2[0].ElementId));
						}
						if (list2[0].PositionFlag == 2)
						{
							if (!this.ConnectPipeSprinklersLoop2(document, ref pipe, list2))
							{
								return false;
							}
						}
						else if (list2[0].PositionFlag == 1)
						{
							xyz = this.ConnectPipeSprinklersLoop1(document, ref pipe, list2, xyz, connectType);
						}
						else if (list2[0].PositionFlag == 3)
						{
							IList<AutoConnectParameter> listParam2 = connectHelper.OrderByOfVector(list2);
							xyz = this.ConnectPipeSprinklersLoop3(document, ref pipe, listParam2, xyz, connectType);
						}
					}
					document.Regenerate();
					list2.Clear();
					num++;
					flag = true;
				}
				result = flag;
			}
			catch (Exception)
			{
				flag = false;
				result = flag;
			}
			return result;
		}

		private bool ConnectPipeSprinklersLoop2(Autodesk.Revit.DB.Document doc, ref Pipe pipe, IList<AutoConnectParameter> listParam)
		{
			bool result = false;
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			foreach (AutoConnectParameter autoConnectParameter in listParam)
			{
				result = hypipeConnect.PipeConnectHSprinklersElbow(ref pipe, doc.GetElementById(autoConnectParameter.ElementId) as FamilyInstance);
			}
			return result;
		}

		private XYZ ConnectPipeSprinklersLoop1(Autodesk.Revit.DB.Document doc, ref Pipe pipe, IList<AutoConnectParameter> listParam, XYZ endPoint, int connectType)
		{
			Pipe pipe2 = pipe;
			XYZ xyz = endPoint;
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			foreach (AutoConnectParameter autoConnectParameter in listParam)
			{
				XYZ xyz2 = xyz;
				Pipe pipe3 = pipe2;
				if (connectType == 1)
				{
					hypipeConnect.PipeConnectHSprinklersTee(ref pipe3, doc.GetElementById(autoConnectParameter.ElementId) as FamilyInstance, ref xyz2);
				}
				else
				{
					hypipeConnect.PipeConnectHSprinklersTakeOff(pipe3, doc.GetElementById(autoConnectParameter.ElementId) as FamilyInstance);
				}
				xyz = xyz2;
				pipe2 = pipe3;
			}
			pipe = pipe2;
			return xyz;
		}

		private XYZ ConnectPipeSprinklersLoop3(Autodesk.Revit.DB.Document doc, ref Pipe pipe, IList<AutoConnectParameter> listParam, XYZ endPoint, int connectType)
		{
			Pipe pipe2 = pipe;
			XYZ result = endPoint;
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			int num = 0;
			for (int i = 0; i < listParam.Count; i++)
			{
				if (listParam[0].IndexOfElement == listParam[i].IndexOfElement)
				{
					num = i;
				}
			}
			if (num != 0)
			{
				IList<Pipe> list = hypipeConnect.PipeConnectHSprinklersCross(ref pipe2, doc.GetElementById(listParam[0].ElementId) as FamilyInstance, doc.GetElementById(listParam[num].ElementId) as FamilyInstance, ref result);
				ConnectHelper connectHelper = new ConnectHelper();
				IList<AutoConnectParameter> listParam2 = new List<AutoConnectParameter>();
				Pipe pipe3 = list[0];
				Pipe pipe4 = list[1];
				if (num > 1)
				{
					if (connectHelper.GetProjectOnPipe(list[0], doc.GetElementById(listParam[1].ElementId), 0.0001) != null)
					{
						listParam2 = this.GetElementOutFirst(doc, listParam, 1);
						this.ConnectPipeSprinklersLoop1(doc, ref pipe3, listParam2, hypipeConnect.GetEndPointOfPipe(list[0], listParam[0].LocationPoint.Point), connectType);
						listParam2 = this.GetElementOutFirst(doc, listParam, num + 1);
						this.ConnectPipeSprinklersLoop1(doc, ref pipe4, listParam2, hypipeConnect.GetEndPointOfPipe(list[1], listParam[num].LocationPoint.Point), connectType);
					}
					else
					{
						listParam2 = this.GetElementOutFirst(doc, listParam, 1);
						this.ConnectPipeSprinklersLoop1(doc, ref pipe4, listParam2, hypipeConnect.GetEndPointOfPipe(list[1], listParam[0].LocationPoint.Point), connectType);
						listParam2 = this.GetElementOutFirst(doc, listParam, num + 1);
						this.ConnectPipeSprinklersLoop1(doc, ref pipe3, listParam2, hypipeConnect.GetEndPointOfPipe(list[0], listParam[num].LocationPoint.Point), connectType);
					}
				}
				else if (num + 1 < listParam.Count)
				{
					if (connectHelper.GetProjectOnPipe(list[0], doc.GetElementById(listParam[num + 1].ElementId), 0.0001) != null)
					{
						listParam2 = this.GetElementOutFirst(doc, listParam, num + 1);
						this.ConnectPipeSprinklersLoop1(doc, ref pipe3, listParam2, hypipeConnect.GetEndPointOfPipe(list[0], listParam[num].LocationPoint.Point), connectType);
					}
					else
					{
						listParam2 = this.GetElementOutFirst(doc, listParam, num + 1);
						this.ConnectPipeSprinklersLoop1(doc, ref pipe4, listParam2, hypipeConnect.GetEndPointOfPipe(list[1], listParam[num].LocationPoint.Point), connectType);
					}
				}
			}
			else if (num == 0)
			{
				new ConnectHelper();
				Pipe pipe5 = null;
				if (connectType == 1)
				{
					pipe5 = hypipeConnect.PipeConnectHSprinklersTee(ref pipe2, doc.GetElementById(listParam[0].ElementId) as FamilyInstance, ref result);
				}
				else
				{
					pipe5 = hypipeConnect.PipeConnectHSprinklersTakeOff(pipe2, doc.GetElementById(listParam[0].ElementId) as FamilyInstance, true);
				}
				IList<AutoConnectParameter> listParam3 = new List<AutoConnectParameter>();
				listParam3 = this.GetElementOutFirst(doc, listParam, num + 1);
				this.ConnectPipeSprinklersLoop1(doc, ref pipe5, listParam3, hypipeConnect.GetEndPointOfPipe(pipe5, listParam[num].LocationPoint.Point), connectType);
			}
			pipe = pipe2;
			return result;
		}

		private IList<AutoConnectParameter> GetElementOutFirst(Autodesk.Revit.DB.Document doc, IList<AutoConnectParameter> listElem, int iPosition)
		{
			IList<AutoConnectParameter> list = new List<AutoConnectParameter>();
			for (int i = iPosition; i < listElem.Count; i++)
			{
				if (i < listElem.Count)
				{
					if (listElem[i].IndexOfElement <= 1)
					{
						break;
					}
					list.Add(listElem[i]);
				}
			}
			return list;
		}

		public static IList<Curve> SortCuves(IList<Curve> curveList)
		{
			if (curveList == null || curveList.Count <= 0)
			{
				return curveList;
			}
			return (from x in curveList
			orderby x.Length
			select x).ToList<Curve>();
		}

		public bool JudgeDistanceIsSatisfy1(SprinklerInfo sprinklerInfo, XYZ finalTempPoint, out Element elem)
		{
			bool result = false;
			elem = null;
			foreach (Element element in sprinklerInfo.AroundSprinklers)
			{
				if (element.Id.IntegerValue != sprinklerInfo.CollisionEle.Id.IntegerValue)
				{
					result = true;
					XYZ point = (element.Location as LocationPoint).Point;
					double num = finalTempPoint.DistanceTo(point);
					double num2 = 7.8740157480314954;
					if (num < num2)
					{
						result = false;
						elem = element;
						break;
					}
				}
			}
			return result;
		}

		public List<List<Curve>> GetLstSignArea(Autodesk.Revit.DB.Document doc, Category lineCategory, List<List<Curve>> mergedRect, List<List<Curve>> lstNotMergeArea, List<Element> lstElemS)
		{
			List<Element> list = new List<Element>();
			List<Element> list2 = new List<Element>();
			foreach (Element element in lstElemS)
			{
				SprinklerInfo sprinklerInfo = new SprinklerInfo();
				sprinklerInfo.CollisionEle = element;
				sprinklerInfo.AroundSprinklers = GroundStorehouseNozzle.GetNearSprinklers(doc, element);
				Element item = null;
				if (!this.JudgeDistanceIsSatisfy1(sprinklerInfo, (element.Location as LocationPoint).Point, out item))
				{
					list.Add(element);
					list2.Add(item);
				}
			}
			List<List<Curve>> list3 = new List<List<Curve>>();
			double num = 0.65616797900262469;
			for (int i = 0; i < list.Count; i++)
			{
				XYZ point = (list[i].Location as LocationPoint).Point;
				XYZ point2 = (list2[i].Location as LocationPoint).Point;
				XYZ xyz = (point - point2).Normalize();
				XYZ xyz2 = (point2 - point).Normalize();
				XYZ item2 = point2 + num * xyz2;
				XYZ item3 = point + num * xyz;
				List<XYZ> list4 = new List<XYZ>();
				list4.Add(item2);
				list4.Add(item3);
				IList<XYZ> list5 = new List<XYZ>();
				IList<XYZ> list6 = new List<XYZ>();
				GroundStorehouseNozzle.OffsetCurve(list4, num * 2.0, out list5, 0.0);
				GroundStorehouseNozzle.OffsetCurve(list4, -num * 2.0, out list6, 0.0);
				list3.Add(new List<Curve>
				{
					Line.CreateBound(list5[0], list5[1]),
					Line.CreateBound(list5[1], list6[1]),
					Line.CreateBound(list6[1], list6[0]),
					Line.CreateBound(list6[0], list5[0])
				});
			}
			for (int j = 0; j < list3.Count; j++)
			{
				if (list3[j].Count != 2)
				{
					for (int k = 0; k < list3[j].Count; k++)
					{
						Curve curve = list3[j][k];
						GroundStorehouseNozzle.DrawCurve(doc.ActiveView, doc, curve, lineCategory);
					}
				}
			}
			return list3;
		}

		public static bool OffsetCurve(IList<XYZ> srcPts, double dOffSet, out IList<XYZ> offsetPoints, double dZOffset = 0.0)
		{
			offsetPoints = new List<XYZ>();
			IList<XYZ> list = new List<XYZ>();
			for (int i = 0; i < srcPts.Count; i++)
			{
				if (i == 0)
				{
					list.Add(srcPts[i]);
				}
				else if (srcPts[i].DistanceTo(list.Last<XYZ>()) > 0.001)
				{
					list.Add(srcPts[i]);
				}
			}
			if (list.Count < 2)
			{
				return false;
			}
			XYZ xyz = new XYZ(0.0, 0.0, 1.0) * dZOffset;
			if (list.Count == 2)
			{
				XYZ xyz2 = list[1] - list[0];
				xyz2 = new XYZ(-xyz2.Y, xyz2.X, 0.0);
				xyz2 = xyz2.Normalize();
				offsetPoints.Add(list[0] - dOffSet * xyz2 + xyz);
				offsetPoints.Add(list[1] - dOffSet * xyz2 + xyz);
				return true;
			}
			for (int j = 1; j < list.Count - 1; j++)
			{
				XYZ xyz3 = list[j - 1];
				XYZ xyz4 = list[j];
				XYZ xyz5 = list[j + 1];
				XYZ xyz6 = xyz4 - xyz3;
				xyz6 = new XYZ(xyz6.X, xyz6.Y, 0.0);
				xyz6 = xyz6.Normalize();
				XYZ xyz7 = new XYZ(-xyz6.Y, xyz6.X, 0.0);
				XYZ xyz8 = xyz5 - xyz4;
				xyz8 = new XYZ(xyz8.X, xyz8.Y, 0.0);
				xyz8 = xyz8.Normalize();
				XYZ xyz9 = new XYZ(-xyz8.Y, xyz8.X, 0.0);
				if (j == 1)
				{
					offsetPoints.Add(xyz3 - dOffSet * xyz7 + xyz);
				}
				if (xyz7.IsAlmostEqualTo(xyz9))
				{
					offsetPoints.Add(xyz4 - dOffSet * xyz7 + xyz);
				}
				else
				{
					XYZ xyz10 = xyz7 + xyz9;
					xyz10 = xyz10.Normalize();
					double d = xyz7.AngleTo(xyz10);
					offsetPoints.Add(xyz4 - dOffSet * xyz10 / Math.Cos(d) + xyz);
				}
				if (j == list.Count - 2)
				{
					offsetPoints.Add(xyz5 - dOffSet * xyz9 + xyz);
				}
			}
			return true;
		}

		public static void TestDraw(Autodesk.Revit.DB.Document doc, Category lineCategory, List<List<Curve>> lstSignArea)
		{
			for (int i = 0; i < lstSignArea.Count; i++)
			{
				if (lstSignArea[i].Count != 2)
				{
					for (int j = 0; j < lstSignArea[i].Count; j++)
					{
						Curve curve = lstSignArea[i][j];
						GroundStorehouseNozzle.DrawCurve(doc.ActiveView, doc, curve, lineCategory);
					}
				}
			}
		}

		public List<Curve> GetClomnCurveList(Autodesk.Revit.DB.Document doc, Element collisionEle, double zValue)
		{
			List<Curve> list = new List<Curve>();
			try
			{
				BoundingBoxXYZ boundingBoxXYZ = collisionEle.get_BoundingBox(doc.ActiveView);
				double x = boundingBoxXYZ.Min.X;
				double x2 = boundingBoxXYZ.Max.X;
				double y = boundingBoxXYZ.Min.Y;
				double y2 = boundingBoxXYZ.Max.Y;
				XYZ xyz = new XYZ(x, y2, zValue);
				XYZ xyz2 = new XYZ(x, y, zValue);
				XYZ xyz3 = new XYZ(x2, y, zValue);
				XYZ xyz4 = new XYZ(x2, y2, zValue);
				Line item = Line.CreateBound(xyz, xyz2);
				Line item2 = Line.CreateBound(xyz2, xyz3);
				Line item3 = Line.CreateBound(xyz3, xyz4);
				Line item4 = Line.CreateBound(xyz4, xyz);
				list.Add(item);
				list.Add(item2);
				list.Add(item3);
				list.Add(item4);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			return list;
		}

		private XYZ GetCurvePoint(List<Curve> lst)
		{
			XYZ xyz = new XYZ();
			foreach (Curve curve in lst)
			{
				xyz += (curve.GetEndPoint(0) + curve.GetEndPoint(1)) / 2.0;
			}
			return xyz / (double)lst.Count;
		}

		public void GetLstLstCurve(Autodesk.Revit.DB.Document doc, Category lineCategory, List<Element> lstRoomRegion, ref List<List<Curve>> lstlstAll)
		{
			ElementFilter elementFilter = new ElementCategoryFilter(BuiltInCategory.OST_Columns);
			ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);
			LogicalOrFilter elementFilter2 = new LogicalOrFilter(elementFilter, elementCategoryFilter);
			IList<Element> elementsByRoomArea = GroundStorehouseNozzle.GetElementsByRoomArea(doc, lstRoomRegion.First<Element>(), elementFilter2);
			if (elementsByRoomArea.Count == 0)
			{
				return;
			}
			List<List<Curve>> list = new List<List<Curve>>();
			foreach (Element element in elementsByRoomArea)
			{
				XYZ point = (element.Location as LocationPoint).Point;
				List<Curve> clomnCurveList = this.GetClomnCurveList(doc, element, point.Z);
				if (GroundStorehouseNozzle.PointInPloygon(lstlstAll.Last<List<Curve>>(), point) == 1)
				{
					list.Add(clomnCurveList);
				}
			}
			List<List<Curve>> list2 = new List<List<Curve>>();
			for (int i = 0; i < lstlstAll.Count - 1; i++)
			{
				bool flag = false;
				foreach (List<Curve> list3 in list)
				{
					if (lstlstAll[i].Count == list3.Count)
					{
						XYZ curvePoint = this.GetCurvePoint(lstlstAll[i]);
						XYZ curvePoint2 = this.GetCurvePoint(list3);
						if (curvePoint.DistanceTo(curvePoint2) < 1.0)
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					list2.Add(lstlstAll[i]);
				}
			}
			foreach (List<Curve> item in list2)
			{
				lstlstAll.Remove(item);
			}
		}

		public LayBasementSprinklerParameter basementManage;

		private XYZ sPoint = new XYZ();

		private List<ElementId> NotSatisfySprinklerId = new List<ElementId>();
	}
}
